How to get multiple objects by id in one call?

I’d like to query multiple Ids but in one call to the server - I am using the client on nodejs.

would

builder.withWhere({
                    path: ["id"],
                    operator: "ContainsAny",
                    valueString: [...ids...]
                });

Assuming there are 10 ids will this definitely find all 10 if they exist? Or are there efficiency limits so that it won’t search the whole database to get all 10? (I know these limits can happen with text/vector searches etc…).

Ie: should I do 10 separate find by id searches to definitely find the objects - or can I safely use the above?

hi @msj242 !!

I believe this is the best way to filter.

Here is a full python v4 example:

from weaviate.util import generate_uuid5
client.collections.delete("Test")

collection = client.collections.create(
    name="Test",
    vectorizer_config=wvc.config.Configure.Vectorizer.none(),
    properties=[
        wvc.config.Property(
            name="text",
            data_type=wvc.config.DataType.TEXT,
            vectorize_property_name=True,
            tokenization=wvc.config.Tokenization.WORD
        ),
    ]
)

for i in range(10):
    collection.data.insert({"text": f"content {i}"}, uuid=generate_uuid5(i))

query = collection.query.fetch_objects(
    filters=wvc.query.Filter.by_property("_id").contains_any([generate_uuid5(1), generate_uuid5(3)])
)

for object in query.objects:
    print(object.properties)

@DudaNogueira Just curious though if “contains_any” will search the database for all the ids - or if there is a limit to the search. I understood text/vector searches have some limit to preserve resources.

Thanks!

Hey @msj242, under the hood, contains_any just builds a filter which is passed into the same search function as any other search. So the global max limit, QUERY_MAXIMUM_RESULTS, will be applied in the same manner :slight_smile:

1 Like