Skip to main content

Set

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 Set request inserts entries into an AI store. The AI server automatically generates embeddings for the provided inputs.

  • Input: Store name, array of entries (input-value pairs), and preprocessing options.

  • Behavior: Generates embeddings for each input and stores them with associated metadata.

  • Response: Confirmation of the operation.

Click to expand source code
TypeScript
import { createAiClient } from "ahnlich-client-node";
import { Set } from "ahnlich-client-node/grpc/ai/query_pb";
import { AiStoreEntry, StoreInput, StoreValue } from "ahnlich-client-node/grpc/keyval_pb";
import { MetadataValue } from "ahnlich-client-node/grpc/metadata_pb";
import { PreprocessAction } from "ahnlich-client-node/grpc/ai/preprocess_pb";

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

await client.set(
new Set({
store: "ai_store",
schema: "analytics",
inputs: [
new AiStoreEntry({
key: new StoreInput({ value: { case: "rawString", value: "Jordan One" } }),
value: new StoreValue({
value: {
brand: new MetadataValue({ value: { case: "rawString", value: "Nike" } }),
},
}),
}),
],
preprocessAction: PreprocessAction.NO_PREPROCESSING,
})
);

console.log("Entry inserted successfully");
}

setEntries();

Parameters

ParameterTypeRequiredDescription
storestringYesThe name of the AI store
inputsAiStoreEntry[]YesArray of entries to insert
preprocessActionPreprocessActionNoPreprocessing to apply to inputs

AiStoreEntry Structure

FieldTypeDescription
keyStoreInputThe input (text or binary) to embed
valueStoreValueMetadata associated with the entry

StoreInput Types

TypeDescription
rawStringText input for text models
imageBinary image data for image models

Example with Multiple Text Entries

Click to expand source code
TypeScript
import { createAiClient } from "ahnlich-client-node";
import { Set } from "ahnlich-client-node/grpc/ai/query_pb";
import { AiStoreEntry, StoreInput, StoreValue } from "ahnlich-client-node/grpc/keyval_pb";
import { MetadataValue } from "ahnlich-client-node/grpc/metadata_pb";
import { PreprocessAction } from "ahnlich-client-node/grpc/ai/preprocess_pb";

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

const products = [
{ name: "Air Jordan 1", brand: "Nike", category: "Basketball" },
{ name: "Ultraboost", brand: "Adidas", category: "Running" },
{ name: "Chuck Taylor", brand: "Converse", category: "Casual" },
];

await client.set(
new Set({
store: "products",
schema: "analytics",
inputs: products.map(
(p) =>
new AiStoreEntry({
key: new StoreInput({ value: { case: "rawString", value: p.name } }),
value: new StoreValue({
value: {
brand: new MetadataValue({ value: { case: "rawString", value: p.brand } }),
category: new MetadataValue({ value: { case: "rawString", value: p.category } }),
},
}),
})
),
preprocessAction: PreprocessAction.NO_PREPROCESSING,
})
);
}

setMultipleEntries();

Example with Binary Image

Click to expand source code
TypeScript
import * as fs from "fs";
import { createAiClient } from "ahnlich-client-node";
import { Set } from "ahnlich-client-node/grpc/ai/query_pb";
import { AiStoreEntry, StoreInput, StoreValue } from "ahnlich-client-node/grpc/keyval_pb";
import { MetadataValue } from "ahnlich-client-node/grpc/metadata_pb";
import { PreprocessAction } from "ahnlich-client-node/grpc/ai/preprocess_pb";

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

const imageData = fs.readFileSync("./product.jpg");

await client.set(
new Set({
store: "image_store",
schema: "analytics",
inputs: [
new AiStoreEntry({
key: new StoreInput({ value: { case: "image", value: imageData } }),
value: new StoreValue({
value: {
filename: new MetadataValue({ value: { case: "rawString", value: "product.jpg" } }),
},
}),
}),
],
preprocessAction: PreprocessAction.NO_PREPROCESSING,
})
);
}

setImageEntry();