Skip to content

JavaScript SDK

The public SDK is bundled and served at:

https://mrhisearch.com/api/demo/sdk.js
import { createMRHIDemoClient } from "https://mrhisearch.com/api/demo/sdk.js";
const client = createMRHIDemoClient({
baseUrl: "https://mrhisearch.com/api/demo",
dimensions: 3,
token: undefined,
});

Options:

  • baseUrl: defaults to the current origin’s /api/demo in the browser
  • dimensions: optional upfront dimension lock for your app
  • token: optional previously saved token
  • fetch: optional custom fetch implementation

If your page is not being served from mrhisearch.com, pass baseUrl: "https://mrhisearch.com/api/demo" explicitly.

import { createMRHIDemoClient } from "https://mrhisearch.com/api/demo/sdk.js";
const client = createMRHIDemoClient({
baseUrl: "https://mrhisearch.com/api/demo",
dimensions: 3,
});
const token = await client.getToken();
console.log("Save this token:", token);
await client.addMany([
{ id: "doc-1", vector: [1, 0, 0], metadata: { label: "alpha", category: "news" } },
{ id: "doc-2", vector: [0.9, 0.1, 0], metadata: { label: "beta", category: "news" } },
{ id: "doc-3", vector: [0, 1, 0], metadata: { label: "gamma", category: "sports" } },
]);
const hasDoc1 = await client.has("doc-1");
const doc1Vector = await client.get("doc-1");
const doc1Metadata = await client.getMetadata("doc-1");
const search = await client.search([1, 0, 0], {
topK: 3,
includeMetadata: true,
filter: { category: "news" },
});
const batch = await client.searchMany(
[
[1, 0, 0],
[0, 1, 0],
],
{
topK: 2,
includeMetadata: true,
},
);
console.log(hasDoc1.has);
console.log(doc1Vector.vector);
console.log(doc1Metadata.metadata);
console.log(search.results);
console.log(search.metrics);
console.log(batch.results);

Use one of these patterns:

const token = await client.getToken();
console.log(token);
const client = createMRHIDemoClient({
baseUrl: "https://mrhisearch.com/api/demo",
token: "mrhi_demo__saved_token",
});
client.useToken("mrhi_demo__saved_token");

Helpful token-related members:

  • client.token
  • client.hasToken()
  • client.getToken()
  • client.ensureToken()
  • client.useToken(token)
  • client.setToken(token)

The public demo supports dimensions up to 1024.

  • You can pass dimensions when creating the client
  • You can also let the first add() or addMany() infer dimensions from the vector length
  • Once the session is initialized, later vectors and queries must match the same dimension
  • Use resetIndex() to fully drop the index and choose a different dimension with the same token
await client.resetIndex();
client.setDimensions(5);
  • limits()
  • createToken()
  • getToken()
  • ensureToken()
  • session()
  • resetIndex()
  • has(id)
  • get(id)
  • getMany(ids)
  • getMetadata(id)
  • setMetadata(id, metadata)
  • deleteMetadata(id)
  • add(id, vector, metadata?, options?)
  • addMany(vectors, options?)
  • delete(id)
  • deleteMany(ids)
  • clear()
  • search(queryVector, options?)
  • searchMany(queryVectors, options?)
  • clear(): removes all vectors but keeps the current session configuration
  • resetIndex(): removes the whole index so the token can be reused with a new dimension or metric

Filters are sent as plain JSON objects and passed through to MRHI’s metadata filtering.

const result = await client.search([1, 0, 0], {
filter: { category: "news" },
includeMetadata: true,
});

Every SDK method returns the raw API payload, including metrics.

Common fields:

  • requestLatencyMs
  • dbOpenMs
  • operation-specific timings like addManyMs, searchMs, or deleteManyMs

The exact metrics depend on the route. See Limits and Metrics.