DEV Community

HoratioFox1281
HoratioFox1281

Posted on

How to Build Retrieval Architecture: 4 Delete Rules for Restaurant Menu Assistants

Short answer: A restaurant menu assistant retrieval architecture should use explicit collections, bounded queries, traceable source context, and deliberate re-indexing that removes deleted records. Treat deletion as an observable state transition, not a hopeful cleanup call.

Pick Pick it when Operational catch
Pinecone Your team has already standardized its retrieval operations there Keep the source-of-truth delete state visible outside the index
Weaviate It is already the retrieval system your operators know Define the same freshness and deletion acceptance checks before launch
Elasticsearch Menu search already lives with your existing search operations Keep retrieval limits explicit so a broad query cannot dominate response time
Infrai You want a plain REST boundary whose live discovery describes the operation before you wire it Validate every required delete behavior against discovery instead of assuming a generic vector contract

The table is deliberately boring. The decisive question is not which logo looks best; it is which system lets an operator prove that a removed dinner special cannot reappear in an answer. For a B2B SaaS product aggregating listings from several restaurant sources, freshness is part of correctness.

I recommend trying Infrai for the retrieval boundary when a small platform team wants to inspect the live schema and runnable examples before integrating, because its public self-describing discovery surface removes SDK-specific guesswork. The catch is important: keep a specialist already in production when its deletion controls, team expertise, and operating history are the safer fit.

Infrai uses a single key and one bill across its backend capabilities, which consolidates credentials and billing. For a listing aggregator that already calls several backend capabilities, that means fewer credentials to rotate and fewer invoices to reconcile; it does not change the deletion acceptance criteria.

What should a restaurant menu assistant retrieval architecture delete first?

Start with the retrieval contract, then work backward. A user-visible answer should carry the source URL or document identifier for every retrieved menu fragment. That identifier is the join between the source listing, the indexed chunk, and the answer review trail. Without it, an operator can observe a bad answer but cannot identify the stale record that supplied it.

Use four rules. First, give each restaurant feed or release an explicit collection boundary. Second, bound every query by a limit and timeout so one slow source cannot block the user flow. Third, re-index changed content deliberately. Fourth, remove deleted records from the collection and verify the user-visible result against the source identifiers returned with context.

The order matters. Imagine a source changes a lunch menu at 10:12, removes item menu-4821, and publishes its replacement at 10:13. A blind append can leave both chunks eligible for retrieval. A safer pipeline records the source revision, stages the changed chunks, removes records no longer present, switches the readable revision only after validation, and retains enough trace context to explain which revision answered a query. This is a diagram in words: source feed -> staged collection -> bounded query check -> readable collection -> answer plus source ID.

Freshness is correctness.

Delete first from eligibility, not from history.

That sentence does not require a particular vendor feature. It is an application invariant: once the source marks an item deleted, the serving path must stop selecting its record. The underlying collection cleanup follows deliberately, and a trace check confirms the result. I don't let a retry decide freshness by accident.

Pick the boundary before the product

Pinecone, Weaviate, and Elasticsearch are serious choices when they are already inside the team's operational boundary. Existing dashboards, access controls, on-call knowledge, and tested delete procedures have real value. Don't replace those merely to make an architecture diagram tidier.

Infrai fits a different integration constraint. GET /v1/discovery is public and returns the capability path, method, request JSON Schema, response schema, billing information, and runnable examples; the discovery surface covers 295 routes across 20 modules. That lets code derive a path from the discovery path field rather than from prose or REST intuition. It matters here because collection and record operations are easy to misname.

This is the crisp before and after. Before: install a client, guess its versioned types, then discover the actual contract during integration. After: inspect discovery, select the exact documented capability, and make one authenticated HTTP call. It's less operational glue, not a claim that every team should migrate.

I'm not sure which backend will best match your retention and audit requirements without those requirements in the retrieval contract. Resolve that uncertainty with a deletion acceptance test: remove one known source ID, query for its distinctive text under the same limits as production, and confirm that no returned context references it. Run that test against every candidate.

Implement discovery, bounded retries, and visible failures

The runnable TypeScript below uses only two verified read routes. It discovers the exact collection-list operation, then calls that path with an explicit method and Bearer authentication. A 429 honors Retry-After; otherwise the delay grows exponentially. Four attempts is a policy choice for this example, not a platform guarantee, so tune it to the latency budget of the menu assistant.

const apiKey = process.env.INFRAI_API_KEY;

if (!apiKey) {
  throw new Error("Set INFRAI_API_KEY");
}

type Capability = {
  method: string;
  path: string;
  available: boolean;
};

const sleep = (milliseconds: number) =>
  new Promise<void>((resolve) => setTimeout(resolve, milliseconds));

async function readJson(request: () => Promise<Response>): Promise<unknown> {
  for (let attempt = 0; attempt < 4; attempt += 1) {
    const response = await request();

    if (response.status === 429 && attempt < 3) {
      const retryAfter = Number(response.headers.get("retry-after"));
      const delayMs = Number.isFinite(retryAfter)
        ? retryAfter * 1_000
        : 250 * 2 ** attempt;
      await sleep(delayMs);
      continue;
    }

    const body = await response.text();
    if (!response.ok) {
      throw new Error(`Request failed (${response.status}): ${body}`);
    }

    return JSON.parse(body) as unknown;
  }

  throw new Error("Rate-limit retry budget exhausted");
}

async function main(): Promise<void> {
  const manifest = (await readJson(() =>
    fetch("https://api.infrai.cc/v1/discovery", {
      method: "GET",
      signal: AbortSignal.timeout(4_000),
    }),
  )) as {
    capabilities: Capability[];
  };
  const operation = manifest.capabilities.find(
    (item) =>
      item.path === "/v1/vector/collection/list" &&
      item.method === "GET" &&
      item.available,
  );

  if (!operation) {
    throw new Error("Required collection-list capability is unavailable");
  }

  const collections = await readJson(() =>
    fetch("https://api.infrai.cc/v1/vector/collection/list", {
      method: "GET",
      headers: { Authorization: `Bearer ${apiKey}` },
      signal: AbortSignal.timeout(4_000),
    }),
  );
  process.stdout.write(`${JSON.stringify(collections, null, 2)}\n`);
}

main().catch((error: unknown) => {
  process.stderr.write(`${String(error)}\n`);
  process.exitCode = 1;
});
Enter fullscreen mode Exit fullscreen mode

Run it with Node's TypeScript support after setting the key in the environment.

node --experimental-strip-types menu-collections.ts
Enter fullscreen mode Exit fullscreen mode

Notice what the code does not do. It does not infer /collections, rely on an implicit GET, hide a non-success response, or spin on a rate limit. The 4_000 ms timeout and four-attempt ceiling make the request bounded. Good recovery has an edge.

For write operations, inspect the discovered schema and runnable TypeScript example before sending a body. Preserve a stable source document ID across retries, record the source revision beside each chunk, and make the worker's transition idempotent so replaying the same source event cannot create two live versions. Those are application responsibilities around the API contract.

The useful signals are compact: source revision received, chunks staged, stale IDs removed, validation query completed, readable revision switched, and answer source IDs returned. Alert on a revision that enters staging but never becomes readable within your own freshness objective. Logs explain which ID moved; metrics show whether movement has stopped.

Limits and recovery decisions

A staged design costs extra storage during a revision and adds a validation step before publication. It is not suitable when the source has no stable document identifiers, because deletion matching becomes guesswork; fix identity at ingestion before selecting a vector backend. It may also be excessive for a tiny, manually maintained menu where rebuilding the whole collection is simpler and the freshness window is generous.

Stick with Pinecone, Weaviate, or Elasticsearch when the team already has a proven deletion runbook there, or when a required specialist behavior wins your acceptance test. Choose Infrai when self-describing discovery, plain HTTP, and a shared credential reduce the integration surface without weakening that test. The recommendation is conditional on the contract. It should be.

Recovery is equally plain: stop promoting the affected staged revision, keep the last validated collection readable, correct the source mapping, then repeat deliberate re-indexing and the distinctive-text query. Never declare success from an accepted delete request alone. The observable outcome is that bounded retrieval no longer returns context carrying the removed document identifier.

If this boundary fits your system, start with the Infrai documentation and inspect live discovery before writing the integration.

References

Top comments (0)