Skip to content

Commit

Permalink
Adding programmatic VS index creation
Browse files Browse the repository at this point in the history
  • Loading branch information
ajosh0504 committed Sep 5, 2024
1 parent 04bccea commit 73a0787
Showing 1 changed file with 37 additions and 25 deletions.
62 changes: 37 additions & 25 deletions notebooks/rag/self_querying_mongodb_unstructured_langgraph.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -821,30 +821,7 @@
"id": "U1nFUwqbtGtS"
},
"source": [
"### MongoDB Atlas Vector Search\n",
"\n",
"To perform vector search, first [create a vector search index](https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-type/) with the following index definition:\n",
"\n",
"```\n",
"{\n",
" \"fields\": [\n",
" {\n",
" \"type\": \"vector\",\n",
" \"path\": \"embeddings\",\n",
" \"numDimensions\": 768,\n",
" \"similarity\": \"cosine\"\n",
" },\n",
" {\n",
" \"type\": \"filter\",\n",
" \"path\": \"metadata.custom_metadata.company\"\n",
" },\n",
" {\n",
" \"type\": \"filter\",\n",
" \"path\": \"metadata.custom_metadata.year\"\n",
" }\n",
" ]\n",
"}\n",
"```"
"### MongoDB Atlas Vector Search"
]
},
{
Expand Down Expand Up @@ -880,6 +857,41 @@
"collection = mongodb_client[MONGODB_DB_NAME][MONGODB_COLLECTION]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"VECTOR_SEARCH_INDEX = \"vector_index\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Create a vector search index\n",
"model = {\n",
" \"name\": VECTOR_SEARCH_INDEX,\n",
" \"type\": \"vectorSearch\",\n",
" \"definition\": {\n",
" \"fields\": [\n",
" {\n",
" \"type\": \"vector\",\n",
" \"path\": \"embeddings\",\n",
" \"numDimensions\": 768,\n",
" \"similarity\": \"cosine\",\n",
" },\n",
" {\"type\": \"filter\", \"path\": \"metadata.custom_metadata.company\"},\n",
" {\"type\": \"filter\", \"path\": \"metadata.custom_metadata.year\"},\n",
" ]\n",
" },\n",
"}\n",
"collection.create_search_index(model=model)"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -908,7 +920,7 @@
" pipeline = [\n",
" {\n",
" \"$vectorSearch\": {\n",
" \"index\": \"vector_index\",\n",
" \"index\": VECTOR_SEARCH_INDEX,\n",
" \"path\": \"embeddings\",\n",
" \"queryVector\": query_embedding,\n",
" \"numCandidates\": 150,\n",
Expand Down

0 comments on commit 73a0787

Please sign in to comment.