Skip to main content

Get by predicate

Retrieve entries by metadata conditions instead of by vector.

Every operation works on both Vector DB stores (you supply raw vectors) and AI stores (you supply text or images and Ahnlich AI generates the embeddings for you). Use the Vector DB / AI switch in the sample below.

Parameters

ParameterTypeDescription
storestringName of the store to read from.
conditionpredicateA metadata predicate, e.g. equals, greater_than. Combine with and/or.
schemastring · optionalSchema to target. Defaults to public.

All requests accept an optional schema field. When omitted, the server uses the public schema.

Behavior

  • Evaluates the predicate against metadata fields and returns every entry that satisfies it.
  • Create a predicate index on the queried fields to keep this fast.

Sample query

Python
import asyncio
from grpclib.client import Channel
from ahnlich_client_py.grpc.services.db_service import DbServiceStub
from ahnlich_client_py.grpc.db import query as db_query
from ahnlich_client_py.grpc import predicates, metadata


async def get_predicate():
async with Channel(host="127.0.0.1", port=1369) as channel:
client = DbServiceStub(channel)

condition = predicates.PredicateCondition(
value=predicates.Predicate(
equals=predicates.Equals(
key="label",
value=metadata.MetadataValue(raw_string="sorcerer")
)
)
)

response = await client.get_pred(
db_query.GetPred(
store="my_store",
schema="analytics",
condition=condition
)
)
# response.entries contains matching items
print(response)

if __name__ == "__main__":
asyncio.run(get_predicate())

Response

A list of all matching entries (vector + metadata).