SDKs
Available

TypeScript

Install @loams/client, make the first call, and run a hybrid query from TypeScript.

@loams/client is one Loams object with namespaced modules over the unified Connect API. The default transport is Connect over fetch, so the same object works in a browser, Node, Deno and Bun. @loams/live carries the generated stubs for Loams Live.

Examples: github.com/ostrium-labs/loams-typescript · Source: sdks/typescript

Install

npm i @loams/client        # and @loams/live for Live's stubs

Quickstart

import { Loams, apiKey, FeatureNotInVariantError } from '@loams/client';

const loams = new Loams({
  endpoint: process.env.LOAMS_ENDPOINT ?? 'http://127.0.0.1:8080',
  auth: apiKey(process.env.LOAMS_API_KEY!), // or envToken(), oidcExchange({...})
});

const info = await loams.instance.getInstance({}); // no auth needed
console.log(info.name, info.apiVersions);

try {
  await loams.system.guard('live'); // costs no RPC once cached
} catch (error) {
  if (error instanceof FeatureNotInVariantError) console.warn(error.variant);
}

For HTTP/2 gRPC on a server, use the Node transport. The /node subpath keeps @connectrpc/connect-node out of browser bundles:

import { Loams, createNodeTransport } from '@loams/client/node';
const loams = new Loams({ endpoint, transport: createNodeTransport() });

Hybrid search from TypeScript

Collections and search are not in the SDK facade in 0.1.0, so call the REST API with fetch. This runs the query from First collection and hybrid search:

const res = await fetch(`${endpoint}/v1/namespaces/demo/query`, {
  method: 'POST',
  headers: { 'content-type': 'application/json', authorization: `Bearer ${process.env.LOAMS_API_KEY}` },
  body: JSON.stringify({
    from: 'collections.kb',
    retrieve: [
      { vector: { field: 'embedding', query: [1, 0, 0], k: 10 } },
      { text: { field: 'body', query: 'refund', k: 10 } },
    ],
    filter: { term: { tenant: 'a' } },
    fuse: { method: 'rrf', k: 60 },
    limit: 3,
  }),
});
console.log(await res.json());

Leave out the authorization header against loams dev with auth off.

Tests

pnpm --filter @loams/client test                                            # the recorded corpus
LOAMS_TEST_ENDPOINT=http://127.0.0.1:8080 pnpm --filter @loams/client test  # a live server

On this page