Skip to main content
Experimental API - Context Connectors is experimental and subject to breaking changes.
Build custom search clients to load indexes and provide search functionality for web apps, CLIs, or serverless functions.

Basic Search Client

import { SearchClient, FilesystemStore } from "@augmentcode/context-connectors";

// Create a search client
const client = new SearchClient({
  store: new FilesystemStore({ basePath: "./indexes" }),
  indexName: "my-docs",
});

// Initialize (loads index from store)
await client.initialize();

// Search
const { results } = await client.search("authentication");
console.log(results);

// Ask a question about the search results
const answer = await client.searchAndAsk(
  "authentication",
  "How does auth work?"
);
console.log(answer);
Search clients load search.json which is optimized for search operations. The full state.json file is only needed by indexers for incremental updates.

Web Application

import express from "express";
import { SearchClient, FilesystemStore } from "@augmentcode/context-connectors";

const app = express();
app.use(express.json());

// Initialize client at startup
const client = new SearchClient({
  store: new FilesystemStore(),
  indexName: "my-docs",
});
await client.initialize();

app.post("/api/search", async (req, res) => {
  const { query } = req.body;
  const { results } = await client.search(query);
  res.json({ results });
});

app.post("/api/ask", async (req, res) => {
  const { query, question } = req.body;
  const answer = await client.searchAndAsk(query, question);
  res.json({ answer });
});

app.listen(3000);

CLI Client

import { program } from "commander";
import { SearchClient, FilesystemStore } from "@augmentcode/context-connectors";

program
  .command("search <query>")
  .option("-i, --index <name>", "Index name", "my-project")
  .action(async (query, options) => {
    const client = new SearchClient({
      store: new FilesystemStore(),
      indexName: options.index,
    });
    await client.initialize();
    const { results } = await client.search(query);
    console.log(results);
  });

program
  .command("ask <query>")
  .option("-i, --index <name>", "Index name", "my-project")
  .option("-q, --question <question>", "Question to ask")
  .action(async (query, options) => {
    const client = new SearchClient({
      store: new FilesystemStore(),
      indexName: options.index,
    });
    await client.initialize();
    const answer = await client.searchAndAsk(query, options.question);
    console.log(answer);
  });

program.parse();

Serverless Function

import { SearchClient, S3Store } from "@augmentcode/context-connectors";

let client: SearchClient | null = null;

async function getClient() {
  if (!client) {
    client = new SearchClient({
      store: new S3Store({ bucket: "my-indexes" }),
      indexName: "my-docs",
    });
    await client.initialize();
  }
  return client;
}

export async function handler(event: any) {
  const body = JSON.parse(event.body || "{}");
  const { query } = body;

  const client = await getClient();
  const { results } = await client.search(query);

  return {
    statusCode: 200,
    body: JSON.stringify({ results }),
  };
}

Next Steps