向量数据库

APOC 提供了一系列过程,利用 REST API 与向量数据库进行交互

  • apoc.vectordb.qdrant.* (用于与 Qdrant 交互)

  • apoc.vectordb.chroma.* (用于与 Chroma 交互)

  • apoc.vectordb.weaviate.* (用于与 Weaviate 交互)

  • apoc.vectordb.custom.* (用于与其它向量数据库交互)。

  • apoc.vectordb.configure (用于将主机、凭据和映射信息存储到系统数据库中)

apoc.vectordb.configure 外,所有过程的最后一个参数都可以是一个包含以下可选参数的配置映射

表 1. 配置参数

键 (key)

description(描述)

headers

附加 HTTP 头信息

method

HTTP 方法

endpoint

端点 (endpoint) 键,可用于覆盖通过过程的第 1 个参数创建的默认端点,以处理潜在的端点更改。

body

HTTP 请求体

jsonPath

用于自定义响应的 JSONPath 解析。默认值为 null

除了上述配置外,apoc.vectordb.<type>.getapoc.vectordb.<type>.query 过程还可以包含以下附加参数

表 2. embeddingConfig 参数

键 (key)

description(描述)

mapping(映射)

用于获取关联实体并可选择性地创建它们。参见下文示例。

allResults

如果为 true,则返回向量、元数据和文本(如果存在),否则这些列将返回 null 值。

vectorKey, metadataKey, scoreKey, textKey

apoc.vectordb.custom.get 过程一起使用。用于告知过程 REST API 中的哪个键(如果存在)对应于应分别填充为向量/元数据/分数/文本结果的键。默认值为 "vector", "metadata", "score", "text"。参见下文示例。

专用过程

有关特定向量数据库过程的更多详细信息,请参阅以下页面

存储向量数据库信息(即 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.*.getAndUpdateapoc.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'
})
© . This site is unofficial and not affiliated with Neo4j, Inc.