向量数据库
APOC 提供了一系列过程,利用 REST API 与向量数据库进行交互
除 apoc.vectordb.configure 外,所有过程的最后一个参数都可以是一个包含以下可选参数的配置映射
键 (key) |
description(描述) |
headers |
附加 HTTP 头信息 |
method |
HTTP 方法 |
endpoint |
端点 (endpoint) 键,可用于覆盖通过过程的第 1 个参数创建的默认端点,以处理潜在的端点更改。 |
body |
HTTP 请求体 |
jsonPath |
用于自定义响应的 JSONPath 解析。默认值为 |
除了上述配置外,apoc.vectordb.<type>.get 和 apoc.vectordb.<type>.query 过程还可以包含以下附加参数
键 (key) |
description(描述) |
mapping(映射) |
用于获取关联实体并可选择性地创建它们。参见下文示例。 |
allResults |
如果为 true,则返回向量、元数据和文本(如果存在),否则这些列将返回 null 值。 |
vectorKey, metadataKey, scoreKey, textKey |
与 |
存储向量数据库信息(即 apoc.vectordb.configure)
我们可以将主机、登录凭据和映射等信息保存在系统数据库中以便稍后重用,这些信息将用于除 apoc.vectordb.custom.get 之外的 *.get 和 .*query 过程。
因此,要存储向量信息,我们可以执行 CALL apoc.vectordb.configure(vectorName, keyConfig, databaseName, $configMap),其中 vectorName 可以是 "QDRANT", "CHROMA", "PINECONE", "MILVUS" 或 "WEAVIATE",分别对应 apoc.vectordb.qdrant.*、apoc.vectordb.chroma.* 和 apoc.vectordb.weaviate.* 重用的信息。
其中 keyConfig 是配置名称,databaseName 是将要设置配置的数据库,
最后是 configMap,它可以包含
-
host是主机基础名称 -
credentialsValue是 API 密钥 -
mapping是一个映射,可供apoc.vectordb.*.getAndUpdate和apoc.vectordb.*.queryAndUpdate过程使用- 注意
-
此过程仅能由具有管理员权限的用户针对系统数据库执行
例如:
// -- within the system database or using the Cypher clause `USE SYSTEM ..` as a prefix
CALL apoc.vectordb.configure('QDRANT', 'qdrant-config-test', 'neo4j',
{
mapping: { embeddingKey: "vect", nodeLabel: "Test", entityKey: "myId", metadataKey: "foo" },
host: 'custom-host-name',
credentials: '<apiKey>'
}
)
然后我们就可以执行例如以下过程(在 neo4j 数据库中)
CALL apoc.vectordb.qdrant.query('qdrant-config-test', 'test_collection', [0.2, 0.1, 0.9, 0.7], {}, 5)
代替
CALL apoc.vectordb.qdrant.query($host, 'test_collection', [0.2, 0.1, 0.9, 0.7], {}, 5,
{ mapping: {
embeddingKey: "vect",
nodeLabel: "Test",
entityKey: "myId",
metadataKey: "foo"
},
headers: {Authorization: 'Bearer <apiKey>'},
endpoint: 'custom-host-name'
})