向量数据库
APOC 提供以下过程集,这些过程利用 Rest API 与向量数据库进行交互
除 apoc.vectordb.configure
过程外,所有过程都可以将包含以下可选参数的配置映射作为最后一个参数
键 |
描述 |
headers |
额外的 HTTP headers |
方法 |
HTTP 方法 |
endpoint |
endpoint 键,可用于覆盖通过过程的第一个参数创建的默认 endpoint,以处理潜在的 endpoint 变更。 |
body |
body HTTP 请求 |
jsonPath |
用于自定义对响应进行 JSONPath 解析。默认为 |
除了上述配置外,apoc.vectordb.<type>.get
和 apoc.vectordb.<type>.query
过程还可以包含以下额外参数
键 |
描述 |
mapping |
用于获取关联实体并可选择创建它们。参见下面的示例。 |
allResults |
如果为 true,则返回向量、元数据和文本(如果存在),否则为这些列返回 null 值。 |
vectorKey, metadataKey, scoreKey, textKey |
与 |
特定过程
有关特定向量数据库过程的更多详细信息,请参见以下页面
存储向量数据库信息(即 apoc.vectordb.configure
)
我们可以在系统数据库中保存一些信息以便以后重用,即主机、登录凭据和映射,用于 *.get
和 .*query
过程,但 apoc.vectordb.custom.get
除外。
因此,要存储向量信息,我们可以执行 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'
})