Skip to content
Snippets Groups Projects
Commit a0909dc0 authored by Marcus Schiesser's avatar Marcus Schiesser Committed by Marcus Schiesser
Browse files

docs: updated how to create a mongodb vector index

parent 853a14b7
Branches
Tags
No related merge requests found
......@@ -45,6 +45,39 @@ async function loadAndIndex() {
await client.close();
}
loadAndIndex();
/**
* This method is document in https://www.mongodb.com/docs/atlas/atlas-search/create-index/#create-an-fts-index-programmatically
* But, while testing a 'CommandNotFound' error occurred, so we're not using this here.
*/
async function createSearchIndex() {
const client = new MongoClient(mongoUri);
const database = client.db(databaseName);
const collection = database.collection(vectorCollectionName);
// define your Atlas Search index
const index = {
name: indexName,
definition: {
/* search index definition fields */
mappings: {
dynamic: true,
fields: [
{
type: "vector",
path: "embedding",
numDimensions: 1536,
similarity: "cosine",
},
],
},
},
};
// run the helper method
const result = await collection.createSearchIndex(index);
console.log("Successfully created search index:", result);
await client.close();
}
loadAndIndex().catch(console.error);
// you can't query your index yet because you need to create a vector search index in mongodb's UI now
......@@ -76,7 +76,7 @@ Now if all has gone well you should be able to log in to the Mongo Atlas UI and
Now it's time to create the vector search index so that you can query the data.
It's not yet possible to programmatically create a vector search index using the [`createIndex`](https://www.mongodb.com/docs/manual/reference/method/db.collection.createIndex/) function, therefore we have to create one manually in the UI.
To do so, first, click the Search tab, and then click "Create Search Index":
To do so, first, click the 'Atlas Search' tab, and then click "Create Search Index":
![MongoDB Atlas create search index](./docs/4_search_tab.png)
......@@ -88,16 +88,14 @@ Now under "database and collection" select `tiny_tweets_db` and within that sele
```json
{
"mappings": {
"dynamic": true,
"fields": {
"embedding": {
"dimensions": 1536,
"similarity": "cosine",
"type": "knnVector"
}
"fields": [
{
"type": "vector",
"path": "embedding",
"numDimensions": 1536,
"similarity": "cosine"
}
}
]
}
```
......
examples/mongodb/docs/4_search_tab.png

230 KiB | W: | H:

examples/mongodb/docs/4_search_tab.png

116 KiB | W: | H:

examples/mongodb/docs/4_search_tab.png
examples/mongodb/docs/4_search_tab.png
examples/mongodb/docs/4_search_tab.png
examples/mongodb/docs/4_search_tab.png
  • 2-up
  • Swipe
  • Onion skin
examples/mongodb/docs/5_json_editor.png

278 KiB | W: | H:

examples/mongodb/docs/5_json_editor.png

147 KiB | W: | H:

examples/mongodb/docs/5_json_editor.png
examples/mongodb/docs/5_json_editor.png
examples/mongodb/docs/5_json_editor.png
examples/mongodb/docs/5_json_editor.png
  • 2-up
  • Swipe
  • Onion skin
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment