Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question]: Weaviate cross-references #13541

Open
1 task done
pedrocr83 opened this issue May 16, 2024 · 1 comment
Open
1 task done

[Question]: Weaviate cross-references #13541

pedrocr83 opened this issue May 16, 2024 · 1 comment
Labels
question Further information is requested weaviate

Comments

@pedrocr83
Copy link

Question Validation

  • I have searched both the documentation and discord for an answer.

Question

I want to create two collections in Weaviate DB and use cross-references. How to implement this and save documents/nodes using VectorStoreIndex?

@pedrocr83 pedrocr83 added the question Further information is requested label May 16, 2024
Copy link

dosubot bot commented May 16, 2024

To create two collections in Weaviate DB and save documents with cross-references using VectorStoreIndex, follow these steps:

  1. Define Your Collections (Schemas): First, define the schema for each collection. For example:

    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)

    This creates two collections with cross-references between them.

  2. Add Documents to Collections: Prepare your documents, ensuring each has a unique identifier and the necessary fields, including references. Use the add method to add documents:

    # 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")

    Replace <uuid_of_collection_one_document> and <uuid_of_collection_two_document> with the actual UUIDs of the documents you are referencing.

  3. Query the Index: After adding documents, you can query the index using Weaviate's query capabilities to perform vector searches or hybrid searches based on your requirements.

Ensure you have weaviate-client installed and set up a connection to your Weaviate instance before proceeding with these steps. This approach will help you effectively manage data and create cross-references between collections in Weaviate.

Details

Sources


About Dosu
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

To continue the conversation, mention @dosu.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested weaviate
Projects
None yet
Development

No branches or pull requests

2 participants