概述
向量存储存储嵌入数据并执行相似性搜索。接口
LangChain 为向量存储提供了统一接口,允许您:add_documents- 将文档添加到存储中。delete- 根据 ID 移除已存储的文档。similarity_search- 查询语义相似的文档。
初始化
要初始化向量存储,需要为其提供一个嵌入模型:添加文档
添加Document 对象(包含 page_content 和可选的元数据),如下:
删除文档
通过指定 ID 删除:相似性搜索
使用similarity_search 发出语义查询,该查询会返回最接近的嵌入文档:
k— 返回的结果数量filter— 基于元数据的条件过滤
相似度指标与索引
嵌入相似度可以使用以下方法计算:- 余弦相似度
- 欧几里得距离
- 点积
元数据过滤
按元数据(例如,来源、日期)过滤可以优化搜索结果:热门集成
选择嵌入模型:OpenAI
OpenAI
Azure
Azure
Google Gemini
Google Gemini
Google Vertex
Google Vertex
AWS
AWS
HuggingFace
HuggingFace
Ollama
Ollama
Cohere
Cohere
Mistral AI
Mistral AI
Nomic
Nomic
NVIDIA
NVIDIA
Voyage AI
Voyage AI
IBM watsonx
IBM watsonx
Fake
Fake
xAI
xAI
Perplexity
Perplexity
DeepSeek
DeepSeek
In-memory
In-memory
AstraDB
AstraDB
Azure Cosmos DB NoSQL
Azure Cosmos DB NoSQL
Azure Cosmos DB Mongo vCore
Azure Cosmos DB Mongo vCore
Chroma
Chroma
FAISS
FAISS
Milvus
Milvus
MongoDB
MongoDB
PGVector
PGVector
PGVectorStore
PGVectorStore
Pinecone
Pinecone
Qdrant
Qdrant
| 向量存储 | 按 ID 删除 | 过滤 | 按向量搜索 | 带分数搜索 | 异步 | 通过标准测试 | 多租户 | 添加文档中的 ID |
|---|---|---|---|---|---|---|---|---|
AstraDBVectorStore | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ✅ |
AzureCosmosDBNoSqlVectorStore | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ |
AzureCosmosDBMongoVCoreVectorStore | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ |
Chroma | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
Clickhouse | ✅ | ✅ | ❌ | ✅ | ❌ | ❌ | ❌ | ✅ |
CouchbaseSearchVectorStore | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ |
DatabricksVectorSearch | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ✅ |
ElasticsearchStore | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ✅ |
FAISS | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ✅ |
InMemoryVectorStore | ✅ | ✅ | ❌ | ✅ | ✅ | ❌ | ❌ | ✅ |
Milvus | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
Moorcheh | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
MongoDBAtlasVectorSearch | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
openGauss | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | ❌ | ✅ |
PGVector | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ✅ |
PGVectorStore | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ |
PineconeVectorStore | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ |
QdrantVectorStore | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ |
Weaviate | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ |
SQLServer | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ |
ZeusDB | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ |