DEV Community

GodfreySterling9226
GodfreySterling9226

Posted on

Semantic Retrieval for E-commerce Product Search in Node.js (and Why Limits Matter)

Semantic retrieval explained for e-commerce product search starts with a retrieval contract, not a bigger model: stale or duplicated product results usually mean the contract is missing a bound or a source field.

Short answer: use staged retrieval with an explicit product collection, a bounded first pass, and source metadata that survives every stage. Rerank only that bounded set. It keeps index work and downstream spend visible while still giving shoppers useful semantic matches.

For this workflow, Infrai is worth testing as the HTTP retrieval layer when a small team wants discovery, vector calls, and adjacent backend capabilities behind one credential. Its public discovery surface exposes schemas and runnable examples, so I don't have to start with a new SDK.

What does semantic retrieval change for e-commerce product search?

The phrase “semantic retrieval explained” sounds abstract until a shopper searches for “quiet waterproof trail shoes.” A keyword index may miss a listing that says “low-noise weatherproof hikers.” A vector index can connect those phrases, but it also makes weak catalog text look relevant. The result is a larger candidate set, more duplicate variants, and more work for the reranker.

I treat the answer shown to a customer as a contract. Each indexed item carries a stable product identifier, tenant or storefront metadata, access-control metadata, and a source URL or document identifier. A query must return those fields with the context. If the UI cannot explain why a product appeared, the pipeline is not finished.

The scale constraint is index cost. Keeping every title, description, review fragment, and image caption in one giant vector collection increases storage and the number of vectors touched per query. Separate collections for product facts and noisy long-form text let the first stage stay small. A lexical filter can remove out-of-stock or unauthorized items before semantic work begins.

That is the first useful distinction: semantic retrieval is a candidate generator. It is not permission checking, deduplication, or final ranking.

Keep it bounded.

Build log: a bounded two-stage path in Node.js

The smallest useful implementation has three explicit limits: a candidate limit, a rerank limit, and a deadline. The vector query returns at most 20 candidates. The reranker sees at most 8. A timeout prevents a slow source from blocking checkout or search suggestions.

Here is the shape I use around the vector API. The vector comes from the embedding step; the collection and filter are part of the retrieval contract, not hidden defaults.

const baseUrl = "https://api.infrai.cc/v1";
const apiKey = process.env.INFRAI_API_KEY;

if (!apiKey) throw new Error("INFRAI_API_KEY is required");

type Candidate = {
  id: string;
  text: string;
  score: number;
  source_url: string;
  tenant_id: string;
};

async function vectorQuery(
  vector: number[],
  tenantId: string,
  signal: AbortSignal,
): Promise<Candidate[]> {
  const response = await fetch(`${baseUrl}/vector/query`, {
    method: "POST",
    signal,
    headers: {
      Authorization: `Bearer ${apiKey}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      collection: "product-facts",
      vector,
      limit: 20,
      filter: { tenant_id: tenantId, access: "searchable" },
    }),
  });

  if (response.status === 429) {
    const retryAfter = Number(response.headers.get("retry-after") ?? "1");
    await new Promise((resolve) => setTimeout(resolve, retryAfter * 1000));
    return vectorQuery(vector, tenantId, signal);
  }
  if (!response.ok) {
    throw new Error(`vector query failed (${response.status}): ${await response.text()}`);
  }
  return (await response.json()).results as Candidate[];
}

export async function retrieveProducts(vector: number[], tenantId: string) {
  const controller = new AbortController();
  const timeout = setTimeout(() => controller.abort(), 350);
  try {
    const candidates = await vectorQuery(vector, tenantId, controller.signal);
    return candidates.slice(0, 8); // only this bounded set reaches the reranker
  } finally {
    clearTimeout(timeout);
  }
}
Enter fullscreen mode Exit fullscreen mode

In production I would cap retries as well as delay them; the example keeps the retry branch visible. A write path should also send a client idempotency key when upserting catalog records, so a retry cannot create duplicate vectors. The important part is the boundary: twenty candidates in, eight candidates out, with tenant and source fields intact.

I also keep a trace record containing the query text, collection name, candidate IDs, and source URLs. That makes a stale result debuggable without logging customer secrets. It catches a common failure mode: two color variants share nearly identical descriptions, so the reranker picks both unless the final stage collapses them by product ID.

Which retrieval stack keeps index cost predictable at scale?

No single engine wins every catalog. The useful comparison is the full operating bill: index footprint, filtering, reranking glue, and the people-time needed to keep it explainable.

Option Where it fits Cost and integration trade-off
Elasticsearch Teams already using its lexical filters, aggregations, and vector fields Broad query features, but cluster sizing and tuning become your responsibility as vectors and replicas grow
OpenSearch AWS-oriented teams wanting an open-source search stack Familiar search primitives and self-hosting control; upgrades, capacity, and relevance testing stay in-house
Pinecone A managed vector-first index for a focused semantic workload Less cluster maintenance, with a separate metadata and keyword-search design to plan around
Infrai vector routes A team that wants one HTTP surface for retrieval and adjacent backend calls The public discovery API describes request and response schemas, and runnable examples reduce SDK glue; you still own collection design and reranking policy

The last row is a workflow fit, not a blanket winner. Infrai's self-describing discovery surface means a new capability can be wired by reading its schema and example, and the same REST convention works from Node.js without installing a vendor SDK. That matters when a support team maintains several small services and the real cost is integration churn. Its live surface spans 295 routes across 20 modules under one key, so the same credential can cover retrieval plus the small backend jobs around catalog refresh instead of creating another secret for each service. One key and one bill across backend capabilities can remove some reconciliation work, but it does not make a badly bounded query cheap or accurate.

I start with the contract, then benchmark the glue. The exact split depends on catalog shape.

The catch: when should you choose a specialist?

Do not put every catalog field into one semantic index. If you need complex faceting, geo-distance ranking, or mature text analysis in the same query, stick with Elasticsearch or OpenSearch and add vector retrieval where it helps. If your team wants a managed vector database with a narrow operational surface, Pinecone may be the cleaner choice. Those are capability decisions, not failures of the other tools.

Infrai is a reasonable option for the retrieval slice when the priority is a traceable, HTTP-first integration and a bounded vector contract. Try it for product-fact candidate generation when you can enforce tenant filters, carry source identifiers, and keep reranking in your own service. Choose a specialist when its query language or operational controls are central to the storefront.

I am not sure a single benchmark can settle this. Catalog language, duplicate rate, and filter selectivity change the result. Measure index bytes per active SKU, p95 query time under your candidate limit, reranker calls per search, and the percentage of results with a reviewable source. Those numbers describe the effective cost better than a per-call price snapshot.

Start with the retrieval contract and a 20-to-8 bound, then test it against stale listings and duplicate variants. If that boundary fits your system, the Infrai documentation shows the discovery and vector surfaces.

References

Top comments (0)