How do I search multiple collections at once?

I am using multiple collections to store data from different sources such as HR and IT support.

I need to query multiple collections at once to extract similar context for LLM model. Please suggest a way to obtain this using weaviate.

Thanks in advance!
Ravi

Hi @Ravi_Puvvula ! Welcome to our community :hugs:

While you can query multiple classes from a same query (using graphql alias), they are independent from each other.

Meaning, you cannot search for one query in both classes and have mixed results. You will end up with two different set of results, each for one class.

Here we have discussed more about it:

Let me know if that helps :slight_smile:

Thanks!

Is there a code sample that shows me how to use GraphQL with a nearText() query to query multiple collections at once? Something using the JS/TS beta syntax?

As you can tell, I’m still unclear on how the whole GraphQL thing maps to the nearText() and other Weaviate WCS client calls. I thought at first GraphQL was just some thing internal to the WCS server side code, not interacted with directly by the developer, but I’m beginning to doubt that assumption is correct.

Also, please don’t lose the partitioned results response as you mentioned above. I want to get the results back with the results from each collection in its own object/array. Please don’t lose this capability in a later release that lets people get a merged result.

hi Robert!

There is a way to perform multiple collection query using a single graphql instruction. That only with GraphQL.

Under the hood, it will perform multiple queries, but you will get all that in a single query.

This is mostly done using GraphQL alias, like so:

 {
   Get {
     Q1: MyClass(tenant: "rep-1") {
       name
     }
     Q2: MyClass(tenant: "rep-2") {
       name
     }
   }
 }

The results of the query will come linked to whatever you define as Q1/Q2/Q3 etc. Note that you will need to use the raw query while using the python/js client

Let me know if this helps you.

Thanks!

Still don’t know what GraphQL is or how to call it. As I said, so far I’ve just done object importing with vectorization and neartText() calls. I think you’re assuming that I know fundamentally what GraphQL is? I don’t. In fact, up until I now, I thought it was an industry standard package like Redis or something.

Oh, ok! Gotcha!

So Graphql is basically a language to specify how you want to query things. The cool feature of it is that you can specify what you want to do and what exact properties you want to get retrieved.

So if you have 100 properties, and only want 2 of them, you can specify that when requesting, and avoid retrieving all the other 98 properties you don’t want.

Weaviate has Graphql implemented in some endpoints (mostly for querying), which means you can pass a graphql query and weaviate will run the results for you.

Now, if you want to call a graphql query using the python client, for example, you can do, using python v4:

my_graphql_query = '''{
   Get {
     Q1: MyClass(tenant: "rep-1") {
       name
     }
     Q2: MyClass(tenant: "rep-2") {
       name
     }
   }
 }'''
client.graphql_raw_query(my_graphql_query)

So, as expected, you can do all sorts of things in graphql, like a neartext, rerank, etc, considering you have those properly configured for your collection.

If you want to do a near text, using graphql directly, you can always check our documentation. There will be a graphql tab, showing how to accomplish that, like in here:

for instance:

{
  Get {
    JeopardyQuestion(
      limit: 2
      nearText: {
        concepts: ["animals in movies"]
      }
    ) {
      question
      answer
      _additional {
        distance
      }
    }
  }
}

If you are not sure how to build you graphql query, check our console. One of the other cool feature of graphql is that it has all the options exposed “inside” the endpoint, which allows graphql clients to build auto complete features:

or, you can navigate in it’s documentation, and check all the available options:

You can learn more about Weaviate’s graphql api here:

Let me know if this helps :slight_smile: