Qdrant 向量存储
🌐 Qdrant Vector Store
QdrantVector 类使用 Qdrant 提供向量搜索,Qdrant 是一个向量相似性搜索引擎。它提供了一个可投入生产的服务,通过便捷的 API 来存储、搜索和管理向量,并支持额外的负载信息和扩展的过滤功能。
🌐 The QdrantVector class provides vector search using Qdrant, a vector similarity search engine. It provides a production-ready service with a convenient API to store, search, and manage vectors with additional payload and extended filtering support.
构造函数选项Direct link to 构造函数选项
🌐 Constructor Options
url:
apiKey:
https:
方法Direct link to 方法
🌐 Methods
createIndex()Direct link to createIndex()
indexName:
dimension:
metric?:
namedVectors?:
创建命名向量集合Direct link to 创建命名向量集合
🌐 Creating a Named Vectors Collection
// Create a collection with multiple named vector spaces
await store.createIndex({
indexName: "multi_modal",
dimension: 768, // fallback
namedVectors: {
text: { size: 768, distance: "cosine" },
image: { size: 512, distance: "euclidean" },
},
});
upsert()Direct link to upsert()
indexName:
vectors:
metadata?:
ids?:
vectorName?:
向命名向量空间上插入或更新Direct link to 向命名向量空间上插入或更新
🌐 Upserting into Named Vector Spaces
// Upsert into the "text" vector space
await store.upsert({
indexName: "multi_modal",
vectors: textEmbeddings,
metadata: textMetadata,
vectorName: "text",
});
// Upsert into the "image" vector space
await store.upsert({
indexName: "multi_modal",
vectors: imageEmbeddings,
metadata: imageMetadata,
vectorName: "image",
});
query()Direct link to query()
indexName:
queryVector:
topK?:
filter?:
includeVector?:
using?:
命名向量Direct link to 命名向量
🌐 Named Vectors
Qdrant 支持命名向量,允许每个集合有多个向量字段。使用 using 参数指定要查询的命名向量:
🌐 Qdrant supports named vectors, allowing multiple vector fields per collection. Use the using parameter to specify which named vector to query against:
const results = await store.query({
indexName: "my_index",
queryVector: embedding,
topK: 10,
using: "title_embedding", // Query against a specific named vector
});
listIndexes()Direct link to listIndexes()
返回一个由索引名称组成的字符串数组。
🌐 Returns an array of index names as strings.
describeIndex()Direct link to describeIndex()
indexName:
返回:
🌐 Returns:
interface IndexStats {
dimension: number;
count: number;
metric: "cosine" | "euclidean" | "dotproduct";
}
deleteIndex()Direct link to deleteIndex()
indexName:
updateVector()Direct link to updateVector()
通过 ID 或元数据过滤器更新单个向量。必须提供 id 或 filter 中的一个,但不能同时提供两者。
🌐 Update a single vector by ID or by metadata filter. Either id or filter must be provided, but not both.
indexName:
id?:
filter?:
update:
在指定索引中更新向量和/或其元数据。如果同时提供向量和元数据,则两者都会被更新。如果只提供其中一个,则只更新该部分。
🌐 Updates a vector and/or its metadata in the specified index. If both vector and metadata are provided, both will be updated. If only one is provided, only that will be updated.
deleteVector()Direct link to deleteVector()
indexName:
id:
根据 ID 删除指定索引的向量。
🌐 Deletes a vector from the specified index by its ID.
deleteVectors()Direct link to deleteVectors()
通过 ID 或元数据过滤器删除多个向量。必须提供 ids 或 filter 中的一个,但不能同时提供两者。
🌐 Delete multiple vectors by IDs or by metadata filter. Either ids or filter must be provided, but not both.
indexName:
ids?:
filter?:
createPayloadIndex()Direct link to createPayloadIndex()
在集合字段上创建一个负载(元数据)索引,以实现高效过滤。这对于 Qdrant Cloud 以及任何带有 strict_mode_config = true 的 Qdrant 实例是必需的。
🌐 Creates a payload (metadata) index on a collection field to enable efficient filtering. This is required for Qdrant Cloud and any Qdrant instance with strict_mode_config = true.
indexName:
fieldName:
fieldSchema:
wait?:
// Create a keyword index for filtering by source
await store.createPayloadIndex({
indexName: "my_index",
fieldName: "source",
fieldSchema: "keyword",
});
const results = await store.query({
indexName: "my_index",
queryVector: queryVector,
filter: { source: "document-a" },
});
deletePayloadIndex()Direct link to deletePayloadIndex()
从集合字段中移除有效负载索引。
🌐 Removes a payload index from a collection field.
indexName:
fieldName:
wait?:
响应类型Direct link to 响应类型
🌐 Response Types
查询结果以此格式返回:
🌐 Query results are returned in this format:
interface QueryResult {
id: string;
score: number;
metadata: Record<string, any>;
vector?: number[]; // Only included if includeVector is true
}
错误处理Direct link to 错误处理
🌐 Error Handling
该存储会抛出可以被捕获的类型化错误:
🌐 The store throws typed errors that can be caught:
try {
await store.query({
indexName: "index_name",
queryVector: queryVector,
});
} catch (error) {
if (error instanceof VectorStoreError) {
console.log(error.code); // 'connection_failed' | 'invalid_dimension' | etc
console.log(error.details); // Additional error context
}
}
相关Direct link to 相关
🌐 Related