Skip to main content

Create Non Linear Algorithm Index

Creates a non-linear index (KDTree or HNSW) to speed up similarity searches in an AI store.

Create a KDTree Index​

Click to expand source code
import { createAiClient } from "ahnlich-client-node";
import { CreateNonLinearAlgorithmIndex } from "ahnlich-client-node/grpc/ai/query_pb";
import { NonLinearIndex, KDTreeConfig } from "ahnlich-client-node/grpc/algorithm/nonlinear_pb";

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

await client.createNonLinearAlgorithmIndex(
new CreateNonLinearAlgorithmIndex({
store: "ai_store",
nonLinearIndices: [
new NonLinearIndex({
index: { case: "kdtree", value: new KDTreeConfig() },
}),
],
})
);

console.log("KDTree index created");
}

createKDTreeIndex();

Create an HNSW Index​

Click to expand source code
import { createAiClient } from "ahnlich-client-node";
import { CreateNonLinearAlgorithmIndex } from "ahnlich-client-node/grpc/ai/query_pb";
import { NonLinearIndex, HNSWConfig } from "ahnlich-client-node/grpc/algorithm/nonlinear_pb";

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

await client.createNonLinearAlgorithmIndex(
new CreateNonLinearAlgorithmIndex({
store: "ai_store",
nonLinearIndices: [
new NonLinearIndex({
index: { case: "hnsw", value: new HNSWConfig() },
}),
],
})
);

console.log("HNSW index created");
}

createHNSWIndex();

Parameters​

ParameterTypeRequiredDescription
storestringYesThe name of the AI store
nonLinearIndicesNonLinearIndex[]YesList of indices to create