How to define a collection with named vectors without using internal embedding models

I know we can define a collection with named vectors with the internal embedding models like below:

    vectorizer_config=[
        # Set a named vector
        wc.Configure.NamedVectors.text2vec_cohere(  # Use the "text2vec-cohere" vectorizer
            name="title", source_properties=["title"]       # Set the source property(ies)
        ),
        # Set another named vector
        wc.Configure.NamedVectors.text2vec_openai(  # Use the "text2vec-openai" vectorizer
            name="body", source_properties=["body"]         # Set the source property(ies)
        )
    ],

What if I want to provide the different named embeddings?

Thanks,
Robert

1 Like

Iā€™d be interested in this as well. How can we bring our own vectors, define a collection with one (or more) named vector(s) and at the same time use our on embedder / embedding function?

In this case I assume that we have to set the Vectorizer to none. But then - how can we set the named vector(s)?

vectorizer_config=wc.Configure.Vectorizer.none(),

I guess that there is a relation to this thread here.

hi @matterberg ! Welcome to our community! :hugs:

Sorry for the delay here, missed this one :frowning:

this is how you can do it using python v4 client:

client.collections.delete("BringOwnNamedVectors")
collection = client.collections.create(
    name="BringOwnNamedVectors",
    description="Collection with named vectors",
    properties=[
        wvc.config.Property(name="name", data_type=wvc.config.DataType.TEXT),
        wvc.config.Property(name="description", data_type=wvc.config.DataType.TEXT),

    ],
    vectorizer_config=[
                    wvc.config.Configure.NamedVectors.none(
                name="named1"
            ),
                    wvc.config.Configure.NamedVectors.text2vec_openai(
                name="named2", source_properties=["name"]
            ),
                    wvc.config.Configure.NamedVectors.text2vec_cohere(
                name="named3", source_properties=["description"]
            )
    ],
)

now you have one object, with tree vectors: named1, named2, named3
named1 as no vectorizer, while named2 and named3 will use openai and cohere respectively.

this is how you can add an object:

collection.data.insert(
    {"name": "object1", "description": "descr1"},
    vector={
        "named1": [1,2,3]
    }
)

As named2 and named3 uses a vectorizer, Weaviate will do it for you. You can now get that object:

object = collection.query.fetch_objects(include_vector=True).objects[0]
print(object.properties)
print(object.vectors)

it will output something like this:

{'description': 'descr1', 'name': 'object1'}
{'named3': [0.01366424560546875, 0.057220458984375, -0.032806396484375, ...], 'named1': [1.0, 2.0, 3.0], 'named2': [-0.025193732231855392, 0.0002761332143563777, -0.014227229170501232, ...]}

Let me know if this helps!

1 Like