Skip to main content

Request AI

The Ahnlich AI Client provides intelligent services that extend the capabilities of the DB client. While the DB client is optimized for storing vectors, managing stores, and retrieving them efficiently, the AI client is responsible for embedding generation, preprocessing, and querying using raw inputs.

Key Features​

  • Raw input support: Accepts text or images as input.

  • Embedding generation: Automatically transforms raw input into embeddings using AI models.

  • AI proxy: Communicates with Ahnlich-DB to persist embeddings and metadata.

  • Query with raw input: No need to manually generate vectors just pass text or images.

  • Flexible models: Choose different models for indexing vs querying.

  • Metadata integration: Store structured information alongside embeddings.

  • Bulk requests: Chain multiple operations (ping, list_stores, etc.) for efficiency.

Supported Raw Inputs​

  • Text - sentences, titles, product descriptions, etc.

  • Images - passed as binary (u8 list).

  • Mixed stores depending on the selected AI model.

Models​

  • Index Model - Used when adding new items (generates embeddings).

  • Query Model - Used when searching (generates query embeddings).

  • You may configure both models separately, but they should be compatible.

Create a Store​

  create_store(
store="my_store",
index_model="all-minilm-l6-v2",
query_model="all-minilm-l6-v2",
)

Insert Raw Input​

Expand code
response = await client.set(
ai_query.Set(
store="my_store",
inputs=[
keyval.AiStoreEntry(
key=keyval.StoreInput(raw_string="Jordan One"),
value=keyval.StoreValue(
value={"brand": metadata.MetadataValue(raw_string="Nike")}
),
),
keyval.AiStoreEntry(
key=keyval.StoreInput(raw_string="Yeezey"),
value=keyval.StoreValue(
value={"brand": metadata.MetadataValue(raw_string="Adidas")}
),
)
],
preprocess_action=preprocess.PreprocessAction.NoPreprocessing
)
)

Query with Raw Input​

Expand code
  response = await client.get_sim_n(
ai_query.GetSimN(
store="my_store",
search_input=keyval.StoreInput(raw_string="Jordan"),
closest_n=3,
algorithm=algorithms.Algorithm.COSINE_SIMILARITY,
)
)

for entry in response.entries:
print(f"Key: {entry.key.raw_string}, Score: {entry.score}")

Below is a breakdown of common AI request examples: