Skip to main content

Quickstart

Go from a running server to your first semantic search in a few minutes. Pick your language once below β€” every code sample on this page follows your choice.

Prerequisites

You need the Ahnlich AI proxy running (it embeds text for you automatically). The fastest way is Docker:

docker run -d --name ahnlich-ai -p 1370:1370 ghcr.io/deven96/ahnlich-ai:latest

See Installation for binaries and other options.

Install the client​

pip install ahnlich-client-py

1. Connect​

Open a client against the AI proxy. No boilerplate, no config.

connect.py
import asyncio
from grpclib.client import Channel
from ahnlich_client_py.grpc.services.ai_service import AiServiceStub


async def main():
# Open a gRPC channel to the AI proxy (default port 1370).
# `async with` closes the connection automatically when you're done.
async with Channel(host="127.0.0.1", port=1370) as channel:
# The stub is your typed client β€” every Ahnlich call goes through it.
client = AiServiceStub(channel)
# ready to talk to Ahnlich

2. Create a store​

Pick an embedding model and let Ahnlich handle the vectors for you.

create_store.py
from ahnlich_client_py.grpc.ai import query as ai_query
from ahnlich_client_py.grpc.ai.models import AiModel

await client.create_store(ai_query.CreateStore(
store="books", # name of the store
index_model=AiModel.ALL_MINI_LM_L6_V2, # model used to embed stored data
query_model=AiModel.ALL_MINI_LM_L6_V2, # model used to embed search queries
predicates=["author", "genre"], # metadata fields you can filter on
store_original=True, # keep the raw text alongside vectors
error_if_exists=True, # fail if a store with this name exists
))
tip

predicates are metadata fields you can later filter on (e.g. author, genre). Field names must match exactly between insert and query.

3. Insert data​

Send raw text with metadata. Embeddings are generated automatically.

insert.py
from ahnlich_client_py.grpc import keyval, metadata
from ahnlich_client_py.grpc.ai import preprocess

await client.set(ai_query.Set(
store="books",
inputs=[
# Each entry = the text to embed (key) + its metadata (value).
keyval.AiStoreEntry(
key=keyval.StoreInput(raw_string="A galactic empire in decline..."),
value=keyval.StoreValue(value={
# These keys must match the store's `predicates` to be filterable.
"genre": metadata.MetadataValue(raw_string="SciFi"),
"author": metadata.MetadataValue(raw_string="Asimov"),
}),
)
],
# ModelPreprocessing lets the proxy tokenize/normalize the text before embedding.
preprocess_action=preprocess.PreprocessAction.ModelPreprocessing,
))

Query by meaning, with results ranked by similarity.

search.py
from ahnlich_client_py.grpc.algorithm import algorithms
from ahnlich_client_py.grpc.ai.preprocess import PreprocessAction

# Search by meaning β€” the query text is embedded with the store's query_model.
response = await client.get_sim_n(ai_query.GetSimN(
store="books",
search_input=keyval.StoreInput(raw_string="space opera classics"),
closest_n=3, # return the 3 nearest matches
algorithm=algorithms.Algorithm.CosineSimilarity, # distance metric
preprocess_action=PreprocessAction.ModelPreprocessing,
))

# Results are ranked most-similar first.
for entry in response.entries:
print(entry.key.raw_string, entry.similarity.value)

That's it β€” you now have semantic search working end to end. πŸŽ‰

Where to next?​

  • Usage β€” drive Ahnlich from the CLI, plus the full command reference.
  • Client Libraries β€” deeper SDK docs for each language.
  • Components β€” how the DB, AI proxy, and CLI fit together.

Found a bug or something unclear? Open an issue.