Qdrant
以下是所有可用的 Qdrant 过程列表,请注意,该列表及过程签名与其他数据库(如 ChromaDB)保持一致。
| 名称 (name) | description(描述) |
|---|---|
apoc.vectordb.qdrant.info(hostOrKey, collection, $config) |
获取指定现有集合的信息,如果集合不存在,则抛出 FileNotFoundException 异常。 |
apoc.vectordb.qdrant.createCollection(hostOrKey, collection, similarity, size, $config) |
创建一个集合,名称由第 2 个参数指定,并具有指定的 |
apoc.vectordb.qdrant.deleteCollection(hostOrKey, collection, $config) |
删除由第 2 个参数指定名称的集合。默认端点为 |
apoc.vectordb.qdrant.upsert(hostOrKey, collection, vectors, $config) |
在第 2 个参数指定的集合中执行 Upsert(插入/更新)操作,传入向量格式为 [{id: 'id', vector: '<vectorDb>', medatada: '<metadata>'}]。默认端点为 |
apoc.vectordb.qdrant.delete(hostOrKey, collection, ids, $config) |
删除具有指定 |
apoc.vectordb.qdrant.get(hostOrKey, collection, ids, $config) |
获取具有指定 |
apoc.vectordb.qdrant.getAndUpdate(hostOrKey, collection, ids, $config) |
获取具有指定 |
apoc.vectordb.qdrant.query(hostOrKey, collection, vector, filter, limit, $config) |
在第 2 个参数指定的集合中,根据定义的 |
apoc.vectordb.qdrant.queryAndUpdate(hostOrKey, collection, vector, filter, limit, $config) |
在第 2 个参数指定的集合中,根据定义的 |
其中,第一个参数可以是 APOC 配置中定义的 key,例如 apoc.qdrant.<key>.host=myHost。若 hostOrKey 为 null,则默认地址为 'https://:6333'。
示例
CALL apoc.vectordb.qdrant.info(hostOrKey, 'test_collection', {<optional config>})
| 值 |
|---|
{"result": {"optimizer_status": "ok", "points_count": 2, "vectors_count": 2, "segments_count": 8, "indexed_vectors_count": 0, "config": {"params": {"on_disk_payload": true, "vectors": {"size": 4, "distance": "Cosine"}, "shard_number": 1, "replication_factor": 1, "write_consistency_factor": 1}, "optimizer_config": {"max_optimization_threads": 1, "indexing_threshold": 20000, "deleted_threshold": 0.2, "flush_interval_sec": 5, "memmap_threshold": null, "default_segment_number": 0, "max_segment_size": null, "vacuum_min_vector_number": 1000}, "quantization_config": null, "hnsw_config": {"max_indexing_threads": 0, "full_scan_threshold": 10000, "ef_construct": 100, "m": 16, "on_disk": false}, "wal_config": {"wal_segments_ahead": 0, "wal_capacity_mb": 32} }, "status": green, "payload_schema": {} }, "time": 1.2725E-4, "status": ok } |
CALL apoc.vectordb.qdrant.createCollection($hostOrKey, 'test_collection', 'Cosine', 4, {<optional config>})
| 结果 | time | 状态 (status) |
|---|---|---|
true |
0.094182458 |
"ok" |
CALL apoc.vectordb.qdrant.deleteCollection($hostOrKey, 'test_collection', {<optional config>})
| 结果 | time | 状态 (status) |
|---|---|---|
true |
0.094182458 |
"ok" |
CALL apoc.vectordb.qdrant.upsert($hostOrKey, 'test_collection',
[
{id: 1, vector: [0.05, 0.61, 0.76, 0.74], metadata: {city: "Berlin", foo: "one"}},
{id: 2, vector: [0.19, 0.81, 0.75, 0.11], metadata: {city: "London", foo: "two"}}
],
{<optional config>})
| 结果 | time | 状态 (status) |
|---|---|---|
{"result": { "operation_id": 0, "status": "acknowledged" } } |
0.094182458 |
"ok" |
CALL apoc.vectordb.qdrant.get($hostOrKey, 'test_collection', [1,2], {<optional config>})
| score | 元数据 (metadata) | id | 向量 (vector) | 文本 (text) | 实体 (entity) |
|---|---|---|---|---|---|
null |
{city: "Berlin", foo: "one"} |
null |
null |
null |
null |
null |
{city: "Berlin", foo: "two"} |
null |
null |
null |
null |
{allResults: true} 的向量CALL apoc.vectordb.qdrant.get($hostOrKey, 'test_collection', [1,2], {allResults: true, <optional config>})
| score | 元数据 (metadata) | id | 向量 (vector) | 文本 (text) | 实体 (entity) |
|---|---|---|---|---|---|
null |
{city: "Berlin", foo: "one"} |
1 |
[…] |
null |
null |
null |
{city: "Berlin", foo: "two"} |
2 |
[…] |
null |
null |
CALL apoc.vectordb.qdrant.query($hostOrKey,
'test_collection',
[0.2, 0.1, 0.9, 0.7],
{ must:
[ { key: "city", match: { value: "London" } } ]
},
5,
{allResults: true, <optional config>})
| score | 元数据 (metadata) | id | 向量 (vector) | 文本 (text) | 实体 (entity) |
|---|---|---|---|---|---|
1, |
{city: "Berlin", foo: "one"} |
1 |
[…] |
null |
null |
0.1 |
{city: "Berlin", foo: "two"} |
2 |
[…] |
null |
null |
我们可以定义映射以获取相关的节点和关系,并利用向量元数据选择性地创建它们。
例如,如果我们通过上述 upsert 过程创建了 2 个向量,我们可以填充一些现有的节点(例如 (:Test {myId: 'one'}) 和 (:Test {myId: 'two'}))
CALL apoc.vectordb.qdrant.queryAndUpdate($hostOrKey, 'test_collection',
[0.2, 0.1, 0.9, 0.7],
{},
5,
{ mapping: {
embeddingKey: "vect",
nodeLabel: "Test",
entityKey: "myId",
metadataKey: "foo"
}
})
这将填充两个节点为:(:Test {myId: 'one', city: 'Berlin', vect: [vector1]}) 和 (:Test {myId: 'two', city: 'London', vect: [vector2]}),它们将在 entity 列结果中返回。
我们还可以将映射配置中的 mode 设置为 CREATE_IF_MISSING(不存在时创建节点)、READ_ONLY(搜索节点/关系,但不进行更新)或 UPDATE_EXISTING(默认行为)。
CALL apoc.vectordb.qdrant.queryAndUpdate($hostOrKey, 'test_collection',
[0.2, 0.1, 0.9, 0.7],
{},
5,
{ mapping: {
mode: "CREATE_IF_MISSING",
embeddingKey: "vect",
nodeLabel: "Test",
entityKey: "myId",
metadataKey: "foo"
}
})
这会像上面一样创建 2 个新节点。
或者,我们可以填充现有关系(例如 (:Start)-[:TEST {myId: 'one'}]→(:End) 和 (:Start)-[:TEST {myId: 'two'}]→(:End))
CALL apoc.vectordb.qdrant.queryAndUpdate($hostOrKey, 'test_collection',
[0.2, 0.1, 0.9, 0.7],
{},
5,
{ mapping: {
embeddingKey: "vect",
relType: "TEST",
entityKey: "myId",
metadataKey: "foo"
}
})
这会填充两个关系为:()-[:TEST {myId: 'one', city: 'Berlin', vect: [vector1]}]-() 和 ()-[:TEST {myId: 'two', city: 'London', vect: [vector2]}]-(),它们将在 entity 列结果中返回。
我们还可以对 apoc.vectordb.qdrant.query 过程使用映射,以搜索符合 label/type 和 metadataKey 的节点/关系,而不进行任何更新(即等同于使用配置 mode: "READ_ONLY" 的 *.queryOrUpdate 过程)。
例如,对于之前的关系,我们可以执行以下过程,该过程仅返回 rel 列中的关系:
CALL apoc.vectordb.qdrant.query($hostOrKey, 'test_collection',
[0.2, 0.1, 0.9, 0.7],
{},
5,
{ mapping: {
relType: "TEST",
entityKey: "myId",
metadataKey: "foo"
}
})
|
我们同样可以在 |
|
为了优化性能,我们可以通过 例如,执行 |
可以将向量数据库过程与 apoc.ml.rag 一起使用,如下所示:
CALL apoc.vectordb.qdrant.getAndUpdate($host, $collection, [<id1>, <id2>], $conf) YIELD node, metadata, id, vector
WITH collect(node) as paths
CALL apoc.ml.rag(paths, $attributes, $question, $confPrompt) YIELD value
RETURN value
这将返回一个字符串,通过利用向量数据库的嵌入(embeddings)来回答 $question。
CALL apoc.vectordb.qdrant.delete($hostOrKey, 'test_collection', [1,2], {<optional config>})
| 结果 | time | 状态 (status) |
|---|---|---|
{"result": { "operation_id": 2, "status": "acknowledged" } } |
0.094182458 |
"ok" |