mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-07 14:03:26 +00:00
LangChain-MongoDB: [Experimental] Driver-side index creation helper (#19359)
## Description Created a helper method to make vector search indexes via client-side pymongo. **Recent Update** -- Removed error suppressing/overwriting layer in favor of letting the original exception provide information. ## ToDo's - [x] Make _wait_untils for integration test delete index functionalities. - [x] Add documentation for its use. Highlight it's experimental - [x] Post Integration Test Results in a screenshot - [x] Get review from MongoDB internal team (@shaneharvey, @blink1073 , @NoahStapp , @caseyclements) - [x] **Add tests and docs**: If you're adding a new integration, please include 1. Added new integration tests. Not eligible for unit testing since the operation is Atlas Cloud specific. 2. an example notebook showing its use. It lives in `docs/docs/integrations` directory.  - [x] **Lint and test**: Run `make format`, `make lint` and `make test` from the root of the package(s) you've modified. See contribution guidelines for more: https://python.langchain.com/docs/contributing/
This commit is contained in:
@@ -143,6 +143,28 @@
|
||||
" }\n",
|
||||
" ]\n",
|
||||
"}\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"Additionally, if you are running a MongoDB M10 cluster with server version 6.0+, you can leverage the `MongoDBAtlasVectorSearch.create_index`. To add the above index its usage would look like this.\n",
|
||||
"\n",
|
||||
"```python\n",
|
||||
"from langchain_community.embeddings.openai import OpenAIEmbeddings\n",
|
||||
"from langchain_mongodb.vectorstores import MongoDBAtlasVectorSearch\n",
|
||||
"from pymongo import MongoClient\n",
|
||||
"\n",
|
||||
"mongo_client = MongoClient(\"<YOUR-CONNECTION-STRING>\")\n",
|
||||
"collection = mongo_client[\"<db_name>\"][\"<collection_name>\"]\n",
|
||||
"embeddings = OpenAIEmbeddings()\n",
|
||||
"\n",
|
||||
"vectorstore = MongoDBAtlasVectorSearch(\n",
|
||||
" collection=collection,\n",
|
||||
" embedding=embeddings,\n",
|
||||
" index_name=\"<ATLAS_VECTOR_SEARCH_INDEX_NAME>\",\n",
|
||||
" relevance_score_fn=\"cosine\",\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"# Creates an index using the index_name provided and relevance_score_fn type\n",
|
||||
"vectorstore.create_index(dimensions=1536)\n",
|
||||
"```"
|
||||
]
|
||||
},
|
||||
@@ -296,6 +318,16 @@
|
||||
" }\n",
|
||||
" ]\n",
|
||||
"}\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"You can also update the index programmatically using the `MongoDBAtlasVectorSearch.create_index` method.\n",
|
||||
"\n",
|
||||
"```python\n",
|
||||
"vectorstore.create_index(\n",
|
||||
" dimensions=1536,\n",
|
||||
" filters=[{\"type\":\"filter\", \"path\":\"page\"}],\n",
|
||||
" update=True\n",
|
||||
")\n",
|
||||
"```"
|
||||
]
|
||||
},
|
||||
|
Reference in New Issue
Block a user