@sinequa/atomic

Similar documents

Finding documents close to one you already have — "more like this" — and cancelling the request when the user moves on.

Given a document, the engine can find others like it. Unlike a search, there is no query text: the source document is the query.

one call
const similar = await client.api.query.similarDocuments(record.id, "<your-query>");

It returns Article[] — the same shape as result.records, so an existing hit-list component renders them without changes.

With cancellation

This call belongs in a panel that follows the user's selection, which means a request is often obsolete before it answers. It is one of the few calls that takes an AbortSignal directly.

A panel that follows the selected document
src/similar.ts
import { createAtomicClient } from "@sinequa/atomic";
import type { Article } from "@sinequa/atomic";

const client = createAtomicClient({
  app: "<your-app>",
  backendUrl: "https://<your-sinequa-server>",
});

await client.initializeConfig();
await client.auth.login();

let inFlight: AbortController | undefined;

export async function showSimilar(recordId: string): Promise<Article[]> {
  // The user can select another document before this one answers.
  inFlight?.abort();
  inFlight = new AbortController();

  try {
    return await client.api.query.similarDocuments(recordId, "<your-query>", inFlight.signal);
  } catch (error) {
    // An aborted request is not a failure to report.
    if (error instanceof DOMException && error.name === "AbortError") return [];
    throw error;
  }
}

Pitfalls

What's next

On this page