Skip to main content

Create predicate index

Index one or more metadata fields so predicate queries run faster.

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
storestringStore to index.
predicateslistMetadata fields to index.
schemastring · optionalSchema to target. Defaults to public.

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

Behavior

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


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

response = await client.create_pred_index(
db_query.CreatePredIndex(
store="my_store",
schema="analytics",
predicates=["label", "category"]
)
)
# response.created_indexes shows how many indexes were created
print(response)


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

Response

The number of indexes successfully created.