向量数据库
APOC 提供了这组过程,利用 Rest API 与向量数据库交互。
除apoc.vectordb.configure
之外的所有过程都可以将一个配置映射作为最后一个参数,其中包含以下可选参数。
键 |
描述 |
headers |
其他 HTTP 标头 |
method |
HTTP 方法 |
endpoint |
端点键,可用于覆盖通过过程的第一个参数创建的默认端点,以处理潜在的端点更改。 |
body |
HTTP 请求体 |
jsonPath |
自定义 JSONPath 响应解析。默认值为 |
除了上述配置之外,apoc.vectordb.<type>.get
和 apoc.vectordb.<type>.query
过程可以具有以下其他参数。
键 |
描述 |
mapping |
用于获取关联的实体并可选地创建它们。请参阅下面的示例。 |
allResults |
如果为真,则返回向量、元数据和文本(如果存在),否则为这些列返回 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'
})