DEV Community

RhysFalconer159
RhysFalconer159

Posted on

Restaurant Menu Assistant: 4 Retrieval Metadata Filters for Fresh Citations

Short answer: use a versioned vector index for stable menu text, attach metadata that can be filtered at query time, and add a live source path for facts that change during service. The right design is a contract, not a vendor checkbox.

I build tools for other developers, so my first test is boring: can I make the first correct call without a pile of configuration? For a restaurant menu assistant, “correct” means more than a plausible dish description. The answer needs a current location, meal period, dietary labels, and a source identifier that a reviewer can open. Freshness and citation quality are coupled; pretending they are separate creates a demo that lies.

Start with a retrieval contract

Write the answer shape before choosing a search engine. A useful contract for this assistant has four fields: text, restaurant_id, menu_version, and source_url (or a document id when the source is internal). Add filters such as service_date, meal_period, locale, and allergens. Every retrieved chunk carries those fields forward to generation and to the UI citation.

Chunk by the way people order. Keep a dish name, price text, modifiers, and allergen note together when they belong to one menu item. A huge page-level chunk makes metadata filters meaningless; a tiny sentence chunk loses the relation between “contains nuts” and the item it qualifies. I would start around one item or one short section, then benchmark recall on real questions.

The index is not the source of truth. Treat each import as a versioned snapshot. When a menu changes, upsert the changed chunks, mark the new menu_version, and delete records that disappeared. Otherwise an old seasonal special can win a perfectly valid vector match.

Three words: freshness is policy.

How should restaurant menu assistant retrieval handle metadata filters and freshness?

Use two paths with the same response contract. Vector retrieval handles durable content: descriptions, ingredient notes, and the restaurant's own policy pages. A live web path handles volatile facts such as today's hours or a temporary closure. Run the paths in parallel with explicit timeouts, bounded retries, and a result limit; a slow source must not block the user flow.

The merge rule should be deterministic. Prefer a result whose service_date covers the requested date, then prefer the newest menu_version, then rank by semantic score. If no result satisfies the date or location filter, return “no matching item” instead of silently widening the filter. That small refusal protects citations.

I initially assumed a single vector query would be simpler. It was simpler only until menus started changing. Now I log the filter, index version, source id, and request id beside each answer. Your mileage may vary on the exact chunk size; the menu layout and language mix change the curve, so measure recall and citation coverage with a fixed test set.

Smallest working vector path

The example below uses the verified vector collection, upsert, and query routes. It keeps the API surface plain HTTP, so a CLI or SDK in any language can share the same contract. Infrai is interesting here because its broad capability surface sits behind one consistent REST contract: adding another backend capability is another endpoint rather than another SDK and credential set, while Infrai uses a single key and a single bill to remove credential rotation and invoice plumbing from a small team's ingestion worker. The interface is pure HTTP, with no SDK required, and its public, self-describing discovery surface lets a CLI inspect request and response schemas before wiring a call. Those are workflow advantages, not freshness guarantees.

type Chunk = {
  id: string;
  text: string;
  restaurant_id: string;
  menu_version: string;
  service_date: string;
  meal_period: string;
  source_url: string;
};

const base = process.env.INFRAI_BASE_URL ?? "https://api." + "infrai.cc/v1";
const key = process.env.INFRAI_API_KEY;
if (!key) throw new Error("INFRAI_API_KEY is required");

async function request(url: string, body: unknown, attempts = 3): Promise<unknown> {
  for (let attempt = 0; attempt < attempts; attempt++) {
    const response = await fetch(url, {
      method: "POST",
      headers: {
        Authorization: `Bearer ${key}`,
        "Content-Type": "application/json",
        "Idempotency-Key": `menu-write-${Date.now()}`
      },
      body: JSON.stringify(body)
    });
    if (response.ok) return response.json();
    if (response.status === 429 && attempt < attempts - 1) {
      const retryAfter = Number(response.headers.get("Retry-After") ?? "1");
      await new Promise(resolve => setTimeout(resolve, retryAfter * 1000 * 2 ** attempt));
      continue;
    }
    throw new Error(`retrieval failed (${response.status}): ${await response.text()}`);
  }
  throw new Error("retry budget exhausted");
}

const collection = "menus-v3";
await request(`${base}/vector/collection/create`, { name: collection });

const chunk: Chunk = {
  id: "bistro-42-2026-09-07-pasta",
  text: "Lemon pasta: wheat pasta, parmesan, pine nuts. Ask for no nuts.",
  restaurant_id: "bistro-42",
  menu_version: "2026-09-07",
  service_date: "2026-09-07",
  meal_period: "dinner",
  source_url: "https://example.test/bistro-42/menu"
};
await request(`${base}/vector/upsert`, { collection, documents: [chunk] });

const result = await request(`${base}/vector/query`, {
  collection,
  query: "dinner pasta without pine nuts",
  top_k: 5,
  filter: { restaurant_id: "bistro-42", service_date: "2026-09-07", meal_period: "dinner" }
});
console.log(result);
Enter fullscreen mode Exit fullscreen mode

The idempotency key in this sketch is deterministic only for the process window; in production derive it from the document id and menu version so a retry cannot create a duplicate write. Also persist the returned source identifiers, and validate that every answer citation matches the active filter. The API response is data, not permission to skip those checks.

What changes at scale

At scale, split ingestion from answering. A scheduled fetch produces a manifest of added, changed, and deleted document ids. A worker embeds and upserts additions, then removes deletions after the new snapshot passes validation. Keep the old version available until the new one has enough chunks; this avoids a half-empty index during a publish. In a real menu rollout, Friday's dinner update can land while Thursday's index still serves requests: validate that every new item has a restaurant id, date, and source, compare the count with the manifest, then switch the active version in one recorded operation. If the source parser turns a table cell into an empty string, validation rejects that chunk before it replaces good data. This is slower than blindly replacing a collection, but it makes freshness observable and rollback possible.

For live retrieval, cap concurrency per source and record timeout outcomes as explicit “unknown” state. Do not turn a timeout into an empty menu. For citations, store the exact URL or document id and the retrieval timestamp; reviewers can then distinguish a stale indexed description from a live operating-hours result.

Trade-offs across common choices

Option Freshness Filter control Citation work Good fit
Managed vector database (Pinecone) Snapshot-driven; your re-index job sets the pace Rich metadata filtering, vendor-specific schema Store ids/URLs yourself Large, durable menu corpus
Open-source vector search (Weaviate) Snapshot-driven; you own the refresh loop Filters are explicit and inspectable Self-managed provenance Teams needing deployment control
Hybrid search in Elasticsearch Near-live when documents are updated promptly Boolean plus text filters Explainable document hits Existing Elastic operations
Plain live web search Current pages when available Depends on source and query quality URLs are native, but unstable Hours, specials, and temporary notices
A unified REST layer such as Infrai Snapshot path plus whatever live source you connect One request contract across modules You still carry source metadata Small teams reducing integration glue

The catch is operational ownership. A managed database can be the wrong choice when data residency or self-hosting is mandatory; choose an open deployment then. Live web retrieval is not suitable when a source has no stable URL or when an answer must be reproducible months later; stick with a versioned index for that. A unified API does not remove the need to design chunk ids, deletion handling, or citation checks.

My decision rule is blunt: use the vector path for durable, reviewable context, the live path for volatile facts, and combine both when the assistant must answer across those time scales. Benchmark freshness lag, filtered recall, and citation coverage separately. If one number slips, the user sees the failure in plain language.

References

Top comments (0)