Skip to main content

Create non-linear index

Add a non-linear index (HNSW) to accelerate similarity search on a store.

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.
non_linear_indiceslistIndex specs — an HnswConfig per index.
schemastring · optionalSchema to target. Defaults to public.

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

Behavior

  • HNSW — approximate nearest-neighbour with a configurable accuracy/speed tradeoff.
  • Pre-structuring the data speeds up queries but uses extra memory.

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.algorithm.nonlinear import NonLinearIndex, HnswConfig


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

# Create an HNSW index (with optional config)
response = await client.create_non_linear_algorithm_index(
db_query.CreateNonLinearAlgorithmIndex(
store="my_store",
schema="analytics",
non_linear_indices=[NonLinearIndex(hnsw=HnswConfig())]
)
)
# response.created_indexes shows how many indexes were created
print(response)


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

Response

The number of indexes created.