Skip to main content

Insert data

Insert one or more entries into a store. Each entry pairs a key (the vector) with a value (its metadata).

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 target store.
inputslist of entriesEach entry is a StoreKey (vector, length must equal the store's dimension) and a StoreValue (map of metadata predicates).
schemastring · optionalSchema to target. Defaults to public.

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

Behavior

  • If a key already exists, its metadata is updated; otherwise a new entry is inserted.
  • Every key's vector length must match the store's dimension.
  • Insert many entries in a single call by passing multiple inputs.

Sample query

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


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

store_key = keyval.StoreKey(key=[1.0, 2.0, 3.0, 4.0])
store_value = keyval.StoreValue(
value={"label": metadata.MetadataValue(raw_string="A")}
)

response = await client.set(
db_query.Set(
store="my_store",
schema="analytics",
inputs=[keyval.DbStoreEntry(key=store_key, value=store_value)]
)
)

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

Response

A confirmation response indicating success.