Skip to main content

Upsert

Schema

This request accepts an optional schema field. When it is omitted, the server uses the public schema. Set schema to target a store in another schema.

The Upsert request updates a single entry matching a predicate condition in an AI store. The AI service automatically merges metadata and can re-embed new inputs.

  • Input: Store name, predicate condition, optional new input/value, preprocessing options.

  • Behavior: Updates exactly one matching entry. AI proxy always merges metadata. Errors on 0 or multiple matches.

  • Response: Upsert counts (inserted and updated).

Click to expand source code
TypeScript
import { createAiClient } from "ahnlich-client-node";
import { Upsert } from "ahnlich-client-node/grpc/ai/query_pb";
import { StoreValue } from "ahnlich-client-node/grpc/keyval_pb";
import { MetadataValue } from "ahnlich-client-node/grpc/metadata_pb";
import { PredicateCondition, Predicate, Equals } from "ahnlich-client-node/grpc/predicates_pb";
import { PreprocessAction } from "ahnlich-client-node/grpc/ai/preprocess_pb";

async function upsertEntry() {
const client = createAiClient("127.0.0.1:1370");

const condition = new PredicateCondition({
kind: {
case: "value",
value: new Predicate({
kind: {
case: "equals",
value: new Equals({
key: "filename",
value: new MetadataValue({ value: { case: "rawString", value: "photo.jpg" } }),
}),
},
}),
},
});

const newValue = new StoreValue({
value: {
tags: new MetadataValue({ value: { case: "rawString", value: "cat,outdoors" } }),
},
});

const response = await client.upsert(
new Upsert({
store: "images",
schema: "media",
condition,
newValue,
preprocessAction: PreprocessAction.NO_PREPROCESSING,
})
);

console.log("Updated:", response.upsert?.updated);
}

upsertEntry();

Parameters

ParameterTypeRequiredDescription
storestringYesThe name of the AI store
conditionPredicateConditionYesMust match exactly one entry
newInputStoreInputNoNew input (text/image) to re-embed
newValueStoreValueNoMetadata to update (always merged)
preprocessActionPreprocessActionNoPreprocessing for new input
executionProviderExecutionProviderNoHardware acceleration (e.g., CUDA)
modelParamsRecord<string, string>NoRuntime model parameters
schemastringNoSchema namespace (defaults to "public")

Behavior

  • AI proxy always merges metadata (preserves AI-generated fields)
  • Predicate must match exactly one entry
  • Re-embeds input if newInput is provided
  • Errors if 0 or multiple entries match
  • Updated entries are immediately available for similarity search