MongoDB Atlas
MongoDB Atlas 是一個完全託管的雲端資料庫,可在 AWS、Azure 和 GCP 中使用。它現在支援 MongoDB 文件資料上的原生向量搜尋。
安裝與設定
請參閱詳細設定指示。
我們需要安裝 langchain-mongodb
python 套件。
pip install langchain-mongodb
向量儲存區
請參閱使用範例。
from langchain_mongodb import MongoDBAtlasVectorSearch
API 參考:MongoDBAtlasVectorSearch
檢索器
全文檢索檢索器
Hybrid Search Retriever
使用 Lucene 的標準 (BM25
) 分析器執行全文檢索。
from langchain_mongodb.retrievers import MongoDBAtlasFullTextSearchRetriever
混合搜尋檢索器
Hybrid Search Retriever
結合向量和全文檢索,透過Reciprocal Rank Fusion
(RRF
) 演算法對它們進行加權。
from langchain_mongodb.retrievers import MongoDBAtlasHybridSearchRetriever
模型快取
MongoDBCache
在 MongoDB 中儲存簡單快取的抽象化。這不使用語意快取,也不需要在產生之前在集合上建立索引。
匯入此快取
from langchain_mongodb.cache import MongoDBCache
API 參考:MongoDBCache
將此快取與您的 LLM 一起使用
from langchain_core.globals import set_llm_cache
# use any embedding provider...
from tests.integration_tests.vectorstores.fake_embeddings import FakeEmbeddings
mongodb_atlas_uri = "<YOUR_CONNECTION_STRING>"
COLLECTION_NAME="<YOUR_CACHE_COLLECTION_NAME>"
DATABASE_NAME="<YOUR_DATABASE_NAME>"
set_llm_cache(MongoDBCache(
connection_string=mongodb_atlas_uri,
collection_name=COLLECTION_NAME,
database_name=DATABASE_NAME,
))
API 參考:set_llm_cache
MongoDBAtlasSemanticCache
語意快取允許使用者根據使用者輸入與先前快取結果之間的語意相似性,檢索快取的提示。在底層,它將 MongoDBAtlas 混合為快取和向量儲存區。MongoDBAtlasSemanticCache 繼承自 MongoDBAtlasVectorSearch
,並且需要定義 Atlas Vector Search 索引才能運作。請查看使用範例,瞭解如何設定索引。
匯入此快取
from langchain_mongodb.cache import MongoDBAtlasSemanticCache
API 參考:MongoDBAtlasSemanticCache
將此快取與您的 LLM 一起使用
from langchain_core.globals import set_llm_cache
# use any embedding provider...
from tests.integration_tests.vectorstores.fake_embeddings import FakeEmbeddings
mongodb_atlas_uri = "<YOUR_CONNECTION_STRING>"
COLLECTION_NAME="<YOUR_CACHE_COLLECTION_NAME>"
DATABASE_NAME="<YOUR_DATABASE_NAME>"
set_llm_cache(MongoDBAtlasSemanticCache(
embedding=FakeEmbeddings(),
connection_string=mongodb_atlas_uri,
collection_name=COLLECTION_NAME,
database_name=DATABASE_NAME,
))
API 參考:set_llm_cache
``