Querying Multiple Collections Dynamically in Weaviate v4

We’re testing Weaviate v4 for our vector database and have two collections (classes) set up. Our users often ask questions where we don’t know which collection contains the relevant answer, so we need to query multiple collections simultaneously.

So far, the best solution I’ve found is using this GraphQL query:

{
  Get {
    Features (
      hybrid: {
        query: "some query..."
        alpha: 0.5
      }
      limit: 5
    ) {
      product
      channel
      _additional { score }
    }
    Banks (
      hybrid: {
        query: "some query..."
        alpha: 0.5
      }
      limit: 5
    ) {
      bank_name
      aBU
      _additional { score }
    }
  }
}

This works, but hardcoding each collection isn’t scalable as more collections are added.

My question:

Is there a way to dynamically query multiple collections in v4 without listing each one manually? Only thing we saw is the Explore method, which is not supported anymore as far as we see.

Thanks in advance!

hi @roei.nuvei !!

Welcome to our community :hugs:

This graphql is the equivalent of calling collection.query.hybrid in sequence :slight_smile:

You can certainly leverage some of the tools that frameworks like langchain or llamaindex has to offer.

Here for example, we have a recipe on how to use llamaindex Router Query Engine:

You basically describe each collection, and it will check how close your query is to each query engine description and decide based on that.

Let me know if this helps.

Thanks!

Hey @DudaNogueira , thanks for the quick response.
My main question is about querying all collections at once, is that supported?
I saw you had the Explore function but it seems to be disabled

Not directly. However we have an async client for python, so you can query them all concurrently by yourself with asyncio.gather (random link that looked ok)

I saw you had the Explore function but it seems to be disabled

Explore is very outdated and basically dead