Querying Multiple Indexes in Weaviate v4

Hi everyone,

I’m currently working with Weaviate and I have a question regarding querying multiple indexes in one go.

Right now, I am using the following code to query a single index:

document_collection = client.collections.get("Document_snap_updated")
response = document_collection.query.near_vector(
    near_vector=query_vector, 
    limit=2,
    return_metadata=MetadataQuery(distance=True)
)

for o in response.objects:
    print(o.properties)
    print(o.metadata.distance)

This works perfectly for querying a single index. However, I would like to know if there is a way to query multiple indexes simultaneously. Ideally, I would like to do something like this:

Python

document_collection = client.collections.get("Document_1", "Document_2", "Document_3")
response = document_collection.query.near_vector(
    near_vector=query_vector, 
    limit=2,
    return_metadata=MetadataQuery(distance=True)
)

for o in response.objects:
    print(o.properties)
    print(o.metadata.distance)

Is there a built-in way to achieve this in Weaviate, or would I need to query each index separately and then merge the results manually? Any guidance or examples would be greatly appreciated.

Thanks in advance for your help!

hi @Abg79 !

You cannot perform one query on multiple indexes.

What you can do is to use, that can be closer to what you want, depending on your use case, is ref2vec-centroid

Here we have a blog post double clicking on that:

Another option would be having multiple vectors per one object (named vectors) and doing a multi target search:

Of course, this may or may not fit your usecase.

Let me know if this helps.

Thanks!