Weaviate
以下是所有可用 Weaviate 过程的列表,请注意,过程列表和签名与其他过程(如 Qdrant 过程)保持一致。
名称 | 描述 |
---|---|
apoc.vectordb.weaviate.createCollection(hostOrKey, collection, similarity, size, $config) |
创建集合,集合名称在第二个参数中指定,并具有指定的 |
apoc.vectordb.weaviate.deleteCollection(hostOrKey, collection, $config) |
删除第二个参数中指定名称的集合。默认端点为 |
apoc.vectordb.weaviate.upsert(hostOrKey, collection, vectors, $config) |
在第二个参数中指定名称的集合中更新或插入向量 [{id: 'id', vector: '<vectorDb>', medatada: '<metadata>'}]. 默认端点为 |
apoc.vectordb.weaviate.delete(hostOrKey, collection, ids, $config) |
删除指定 |
apoc.vectordb.weaviate.get(hostOrKey, collection, ids, $config) |
获取指定 |
apoc.vectordb.weaviate.query(hostOrKey, collection, vector, filter, limit, $config) |
从定义的 |
apoc.vectordb.weaviate.getAndUpdate(hostOrKey, collection, ids, $config) |
获取指定 |
apoc.vectordb.weaviate.queryAndUpdate(hostOrKey, collection, vector, filter, limit, $config) |
从定义的 |
其中第一个参数可以是apoc配置apoc.weaviate.<key>.host=myHost
定义的键。当hostOrKey=null时,默认为'http://localhost:8080/v1'。
示例
CALL apoc.vectordb.weaviate.createCollection($host, 'test_collection', 'Cosine', 4, {<optional config>})
CALL apoc.vectordb.weaviate.createCollection("https://<weaviateInstanceId>.weaviate.network",
'TestCollection',
'cosine',
4,
{headers: {Authorization: 'Bearer <apiKey>'}})
CALL apoc.vectordb.weaviate.deleteCollection($host, 'test_collection', {<optional config>})
CALL apoc.vectordb.weaviate.upsert($host, 'test_collection',
[
{id: "8ef2b3a7-1e56-4ddd-b8c3-2ca8901ce308", vector: [0.05, 0.61, 0.76, 0.74], metadata: {city: "Berlin", foo: "one"}},
{id: "9ef2b3a7-1e56-4ddd-b8c3-2ca8901ce308", vector: [0.19, 0.81, 0.75, 0.11], metadata: {city: "London", foo: "two"}}
],
{<optional config>})
CALL apoc.vectordb.weaviate.get($host, 'test_collection', [1,2], {<optional config>})
得分 | 元数据 | ID | 向量 | 文本 | 实体 | 错误 |
---|---|---|---|---|---|---|
空 |
{city: "Berlin", foo: "one"} |
空 |
空 |
空 |
空 |
空 |
空 |
{city: "Berlin", foo: "two"} |
空 |
空 |
空 |
空 |
空 |
{allResults: true}
获取向量CALL apoc.vectordb.weaviate.get($host, 'test_collection', [1,2], {allResults: true, <optional config>})
得分 | 元数据 | ID | 向量 | 文本 | 实体 | 错误 |
---|---|---|---|---|---|---|
空 |
{city: "Berlin", foo: "one"} |
1 |
[…] |
空 |
空 |
空 |
空 |
{city: "Berlin", foo: "two"} |
2 |
[…] |
空 |
空 |
空 |
CALL apoc.vectordb.weaviate.query($host,
'test_collection',
[0.2, 0.1, 0.9, 0.7],
'{operator: Equal, valueString: "London", path: ["city"]}',
5,
{fields: ["city", "foo"], allResults: true, <other optional config>})
得分 | 元数据 | ID | 向量 | 文本 | 错误 |
---|---|---|---|---|---|
1, |
{city: "Berlin", foo: "one"} |
1 |
[…] |
空 |
空 |
0.1 |
{city: "Berlin", foo: "two"} |
2 |
[…] |
空 |
空 |
如果发生错误,例如由于apoc.vectordb.weaviate.query
的第三个参数向量大小错误,则错误字段将被填充,例如
得分 | 元数据 | ID | 向量 | 文本 | 错误 |
---|---|---|---|---|---|
空 |
空 |
空 |
空 |
空 |
..向量搜索:knn搜索:入口点和查询节点之间的距离:向量长度不匹配:4 vs 3.. |
我们可以定义一个映射,通过利用向量元数据来获取关联的节点和关系,并可选地创建它们。
例如,如果我们使用上述upsert过程创建了2个向量,我们可以填充一些现有的节点(即(:Test {myId: 'one'})
和(:Test {myId: 'two'})
)
CALL apoc.vectordb.weaviate.queryAndUpdate($host, 'test_collection',
[0.2, 0.1, 0.9, 0.7],
{},
5,
{ fields: ["city", "foo"],
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.weaviate.queryAndUpdate($host, 'test_collection',
[0.2, 0.1, 0.9, 0.7],
{},
5,
{ fields: ["city", "foo"],
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.weaviate.queryAndUpdate($host, 'test_collection',
[0.2, 0.1, 0.9, 0.7],
{},
5,
{ fields: ["city", "foo"],
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.weaviate.query
过程,以搜索符合标签/类型和元数据键的节点/关系,而不进行更新(即等效于映射配置具有mode: "READ_ONLY"
的*.queryOrUpdate
过程)。
例如,使用先前的关系,我们可以执行以下过程,它只在rel
列中返回关系
CALL apoc.vectordb.weaviate.query($host, 'test_collection',
[0.2, 0.1, 0.9, 0.7],
{},
5,
{ fields: ["city", "foo"],
mapping: {
relType: "TEST",
entityKey: "myId",
metadataKey: "foo"
}
})
我们也可以将映射与 |
为了优化性能,我们可以选择使用apoc.vectordb.weaviate.query和 例如,通过执行 |
可以将向量数据库过程与apoc.ml.rag一起执行,如下所示
CALL apoc.vectordb.weaviate.getAndUpdate($host, $collection, [<id1>, <id2>], $conf) YIELD score, node, metadata, id, vector
WITH collect(node) as paths
CALL apoc.ml.rag(paths, $attributes, $question, $confPrompt) YIELD value
RETURN value
CALL apoc.vectordb.weaviate.delete($host, 'test_collection', [1,2], {<optional config>})
性能
下表显示了在100,000条记录样本上所有操作花费的时间,使用具有8个CPU、内存限制10GB和交换空间1.5GB的Docker在MacBook Pro M3 Pro 18GB Ram上进行测试。
操作 | 时间(毫秒) |
---|---|
apoc.vectordb.weaviate.createCollection |
59 |
apoc.vectordb.weaviate.upsert |
319766 |
apoc.vectordb.weaviate.get |
41431 |
apoc.vectordb.weaviate.query |
1887 |
apoc.vectordb.weaviate.delete |
53218 |
apoc.vectordb.weaviate.deleteCollection |
201 |