JavaScript SDK
The public SDK is bundled and served at:
https://mrhisearch.com/api/demo/sdk.jsImport the client
Section titled “Import the client”import { createMRHIDemoClient } from "https://mrhisearch.com/api/demo/sdk.js";Create a client
Section titled “Create a client”const client = createMRHIDemoClient({ baseUrl: "https://mrhisearch.com/api/demo", dimensions: 3, token: undefined,});Options:
baseUrl: defaults to the current origin’s/api/demoin the browserdimensions: optional upfront dimension lock for your apptoken: optional previously saved tokenfetch: optional customfetchimplementation
If your page is not being served from mrhisearch.com, pass baseUrl: "https://mrhisearch.com/api/demo" explicitly.
Full example
Section titled “Full example”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);Token handling
Section titled “Token handling”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.tokenclient.hasToken()client.getToken()client.ensureToken()client.useToken(token)client.setToken(token)
Dimension handling
Section titled “Dimension handling”The public demo supports dimensions up to 1024.
- You can pass
dimensionswhen creating the client - You can also let the first
add()oraddMany()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);Available methods
Section titled “Available methods”Session + limits
Section titled “Session + limits”limits()createToken()getToken()ensureToken()session()resetIndex()
Vectors
Section titled “Vectors”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
Section titled “Search”search(queryVector, options?)searchMany(queryVectors, options?)
clear() vs resetIndex()
Section titled “clear() vs resetIndex()”clear(): removes all vectors but keeps the current session configurationresetIndex(): removes the whole index so the token can be reused with a new dimension or metric
Filters
Section titled “Filters”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,});Metrics
Section titled “Metrics”Every SDK method returns the raw API payload, including metrics.
Common fields:
requestLatencyMsdbOpenMs- operation-specific timings like
addManyMs,searchMs, ordeleteManyMs
The exact metrics depend on the route. See Limits and Metrics.