[Question] Named Vectors with non-default hnsw

hey,
I’m trying to follow along with the tutorial in the documentation using the python client and I’m getting an unexpected error.

First, I created a collection with non-default hnsw configuration, like this:

client.collections.create(
    "Article0",
    vector_index_config=Configure.VectorIndex.hnsw(ef=123),
    properties=[
        Property(name="title", data_type=DataType.TEXT),
        Property(name="body", data_type=DataType.TEXT),
    ],
)

this seems to work fine.

Then, I created another collection with multiple named vectors, like this:

client.collections.create(
    "Article1",
    vectorizer_config=[
        Configure.NamedVectors.none(name="vector_1"),
        Configure.NamedVectors.none(name="vector_2")
    ],
    properties=[
        Property(name="title", data_type=DataType.TEXT),
        Property(name="body", data_type=DataType.TEXT),
    ],
)

this also worked fine.

However, when I tried to make a single collection with both specifications:

client.collections.create(
    "Article2",
    vector_index_config=Configure.VectorIndex.hnsw(ef=123),
    vectorizer_config=[Configure.NamedVectors.none(name="vector_1"),
                      Configure.NamedVectors.none(name="vector_2")],
    properties=[
        Property(name="title", data_type=DataType.TEXT),
        Property(name="body", data_type=DataType.TEXT),
    ],
)

I got an error:

UnexpectedStatusCodeError: Collection may not have been created properly.! Unexpected status code: 422, with response body: {'error': [{'message': 'class.vectorIndexType "hnsw" can not be set if class.vectorConfig is configured'}]}.

What am I doing wrong? I tried some workaround (such as changed hnsw default after creating the collection), but no luck either. The error itself is a bit curious, because in the second collection (Article1), the vector_index_config is by default hnsw, just with a different ef value.

thanks for the help!

Hi @Omer_Elinav !

Welcome to our community! :hugs:

Indeed this is not possible. Because you are defining named vectors, the index configuration is now a “per named vector basis” and not on a collection basis.

With that said, this is the correct way to “tweak” a named vector index configuration:

from weaviate import classes as wvc
client.collections.delete("Test")
client.collections.create(
    "Test",
    vectorizer_config=[
        wvc.config.Configure.NamedVectors.none(
            name="vector_1"
        ),
        wvc.config.Configure.NamedVectors.none(
            name="vector_2", 
            vector_index_config=wvc.config.Configure.VectorIndex.hnsw(ef=123)
        )
    ],
    properties=[
        wvc.config.Property(name="title", data_type=wvc.config.DataType.TEXT),
        wvc.config.Property(name="body", data_type=wvc.config.DataType.TEXT),
    ],
)

Let me know if that helps!

Thanks!

Let me know if that helps! Thanks!

1 Like