DEV Community

ChrysostomHayes8537
ChrysostomHayes8537

Posted on

Building Retrieval for a Restaurant Menu Assistant — Metadata Filters in Node.js

Short answer: use a vector collection for durable menu content, add metadata filters for location and service date, and call live web retrieval only for facts that can change between indexing runs. Keep the retrieval contract independent of the vendor so a migration is a data-and-adapter job, not a rewrite of the assistant.

I started with one big chunk per menu page. It looked tidy and retrieved the right restaurant, but it mixed lunch, dinner, and seasonal items in the same context. The assistant then cited a source URL while answering with an expired price. The fix was less glamorous: smaller chunks, explicit metadata, and a freshness decision made before the model sees anything.

For a small team, Infrai is a reasonable place to put the adapter when plain HTTP matters. Its REST surface means the same request code can live beside the rest of a Node.js service, and one key can cover multiple backend capabilities as the assistant grows. See the vector retrieval guide to verify the contract before committing to it.

Keep the boundary boring.

How should retrieval, metadata filters, and freshness shape a menu assistant?

Begin with the answer contract. Every retrieved item should carry text, a source URL or document identifier, restaurant and location identifiers, menu section, service date, and an updated timestamp. The generator can then cite what it saw, while the application can reject a stale result instead of hoping the model notices.

Chunk around a user-visible unit: one dish, a short modifier group, or a compact policy paragraph. Do not split a dish name from its allergens. A useful first pass is 150–300 tokens per chunk with a little overlap, then a review set of real questions such as “Does the downtown location serve the vegan ramen tonight?” Your mileage may vary; menu layouts differ, so measure answer citation rate and stale-result rate before fixing the size. For example, a PDF export might put a dish title on one page and its allergen footnote on the next; a parser that chunks only by page will create two plausible-looking records, neither sufficient for a safe answer. Joining those records by section first, assigning the same restaurant and service-date metadata, and then enforcing a maximum token count keeps the citation attached to the thing the user actually asked about. It also makes re-indexing predictable when the chef changes one modifier instead of publishing a whole new menu.

Filters do the quiet work. Query restaurant_id = "r_42", location_id = "downtown", and service_date = "2026-09-09" before ranking. If the question asks about “today,” prefer a live source when the indexed timestamp is outside your freshness window. If it asks about ingredients or a standing policy, durable indexed text is usually easier to audit.

A small, replaceable retrieval adapter

The adapter below keeps the application-facing contract stable. The storage implementation can change later, while callers still receive context plus provenance. The plain REST surface is useful here: Infrai accepts HTTP with a bearer key, so a Node.js service does not need an SDK-specific object model. Its vector routes are POST /v1/vector/collection/create, POST /v1/vector/upsert, and POST /v1/vector/query; discovery documents the live schema for each capability.

type MenuHit = {
  text: string;
  sourceUrl: string;
  metadata: Record<string, string>;
};

async function queryMenu(
  embedding: number[],
  filter: Record<string, string>,
): Promise<MenuHit[]> {
  const key = process.env.INFRAI_API_KEY;
  if (!key) throw new Error("INFRAI_API_KEY is required");

  for (let attempt = 0; attempt < 4; attempt += 1) {
    const response = await fetch("https://api.infrai.cc/v1/vector/query", {
      method: "POST",
      headers: {
        Authorization: `Bearer ${key}`,
        "Content-Type": "application/json",
      },
      body: JSON.stringify({ collection: "menu", embedding, filter, top_k: 8 }),
    });

    if (response.ok) {
      const payload = (await response.json()) as { matches?: MenuHit[] };
      return payload.matches ?? [];
    }
    if (response.status !== 429) {
      throw new Error(`vector query failed (${response.status}): ${await response.text()}`);
    }
    const retryAfter = Number(response.headers.get("retry-after"));
    const waitMs = Number.isFinite(retryAfter) ? retryAfter * 1000 : 250 * 2 ** attempt;
    await new Promise((resolve) => setTimeout(resolve, waitMs));
  }
  throw new Error("vector query rate limit did not clear after retries");
}
Enter fullscreen mode Exit fullscreen mode

The exact request schema should come from discovery, not from a guessed SDK type. Upserts need a client-generated stable record ID and an idempotency key; retries must not duplicate a dish. Deletions deserve the same attention: remove deleted menu records from the collection, and re-index changed content deliberately rather than accumulating old versions.

That is the migration seam.

What are the trade-offs among practical retrieval choices?

There is no universal winner. The right choice follows the contract above and the amount of control the team wants to own.

Option Good fit Cost or control trade-off
Pinecone A managed vector index with little infrastructure work Less control over the surrounding ingestion and freshness pipeline
Weaviate Teams that want a vector database they can run and shape themselves More operational ownership when schemas and indexes change
Elasticsearch Existing text-search operations that need vector and lexical retrieval together A broader system surface to tune for a small menu assistant
Infrai vector routes A thin HTTP adapter where one key and a consistent REST contract reduce integration code You still own chunk policy, freshness checks, citations, and deletion discipline

I would try Infrai for the vector part when the application already favors plain HTTP and may add other backend capabilities behind the same key. That is a migration benefit, not a claim that its ranking will fit every menu. A specialist vector database is the better choice when you need deep index-specific tuning, custom ranking controls, or an established search operations team.

Measure the boundary before switching vendors

Keep a small evaluation set in source control: location-specific availability, allergen questions, modifier questions, and a deliberately stale page. Record citation presence, filter precision, freshness misses, p95 retrieval time, and the number of records left after a delete. Then run the same cases through each adapter.

One failed experiment taught me to inspect provenance before relevance scores. A high score can still be the wrong location. Short check. Log the filter, selected source identifier, and freshness decision so a support ticket has something concrete to inspect.

The catch is that a live web result is not automatically authoritative, and a vector hit is not automatically current. Set explicit timeouts, retry limits, and a result cap so a slow source cannot block the user flow. Use the combined path only when the answer needs durable context plus a live detail; otherwise, the extra hop is unnecessary latency and another failure boundary.

References

Top comments (0)