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β
| Parameter | Type | Required | Description |
|---|---|---|---|
store | string | Yes | The name of the AI store |
nonLinearIndices | NonLinearIndex[] | Yes | List of indices to create |