llama_index [问题]:Weaviate交叉引用

unftdfkk  于 2个月前  发布在  其他
关注(0)|答案(1)|浏览(63)

问题验证

  • 我已在文档和Discord中寻找答案。

问题

我想在Weaviate DB中创建两个集合并使用交叉引用。如何实现这一点,并使用VectorStoreIndex保存文档/节点?

zdwk9cvp

zdwk9cvp1#

在Weaviate数据库中创建两个集合并使用VectorStoreIndex保存具有交叉引用的文档,请按照以下步骤操作:

  1. 定义你的集合(模式):首先,为每个集合定义模式。例如:
schema = {
    "classes": [
        {
            "class": "CollectionOne",
            "properties": [
                {"name": "name", "dataType": ["string"]},
                {"name": "referenceToTwo", "dataType": ["CollectionTwo"]}
            ],
        },
        {
            "class": "CollectionTwo",
            "properties": [
                {"name": "description", "dataType": ["string"]},
                {"name": "referenceToOne", "dataType": ["CollectionOne"]}
            ],
        }
    ]
}
client.schema.create(schema)

这将在它们之间创建交叉引用的两个集合。

  1. 向集合中添加文档:准备你的文档,确保每个文档都有一个唯一的标识符和必要的字段,包括引用。使用 add 方法添加文档:
# Example document for CollectionOne
document_one = {
    "name": "Example Name",
    "referenceToTwo": [
        {
            "beacon": "weaviate://localhost/CollectionTwo/<uuid_of_collection_two_document>"
        }
    ]
}

# Example document for CollectionTwo
document_two = {
    "description": "Example Description",
    "referenceToOne": [
        {
            "beacon": "weaviate://localhost/CollectionOne/<uuid_of_collection_one_document>"
        }
    ]
}

# Add documents to Weaviate
client.data_object.create(data_object=document_one, class_name="CollectionOne")
client.data_object.create(data_object=document_two, class_name="CollectionTwo")

<uuid_of_collection_one_document><uuid_of_collection_two_document> 替换为你正在引用的文档的实际UUID。

  1. 查询索引:在添加文档后,你可以使用Weaviate的查询功能根据你的需求对索引进行查询,执行基于向量的搜索或混合搜索。
    在继续这些步骤之前,请确保已安装 weaviate-client 并设置到Weaviate示例的连接。这种方法将帮助你有效地管理数据并在Weaviate中创建集合之间的交叉引用。
详细信息

来源

此响应旨在帮助您节省时间并提高效率。它不是精确解决方案,而是您自己研究的起点。
请帮助我变得更有用!如果这有帮助,请留下一个👍,如果无关紧要,请留下一个👎。

  • 要继续对话,请提及@dosu。*

相关问题