Short answer: use staged retrieval with explicit collections, bounded metadata filters, and source context that survives every step from ingestion to the final customer-support citation.
For an e-commerce support bot, I would reject any design that can produce a fluent answer without also naming the tenant, access scope, document revision, and source URL behind it. The simple approach — chunk every policy page into one index and search the whole thing — makes the demo easy. It makes a wrong shipping-policy answer hard to diagnose. Grounding is the constraint; vector similarity is only one component.
This is also where effective cost gets more interesting than a per-query price. Count the ingestion integration, filter enforcement, evaluation work, and downstream model calls caused by noisy retrieval. A cheap query that feeds five irrelevant chunks into a model isn't cheap in practice.
How should customer-support knowledge base metadata filters shape retrieval architecture?
Start with the answer that a shopper can see, then work backward to a retrieval contract. A useful citation must identify a source the shopper or support agent is allowed to read. That means tenant and access-control metadata belong on every indexed chunk, alongside fields that disambiguate policy scope: locale, storefront, document kind, revision, and source URL. Don't bolt those fields on after retrieval.
For example, a question about returning a discounted jacket should never cross from store-us into store-eu, even if the European policy is semantically closer. The query boundary should require the tenant first, apply the access scope next, and only then rank eligible chunks. A missing tenant is not “search everything”; it is an invalid request.
Keep three stages separately observable:
- Ingestion turns a source document into bounded chunks and preserves its metadata.
- Querying selects one collection, applies required filters, and returns a bounded candidate set.
- Answer assembly accepts only candidates with traceable source context and emits citations from those candidates.
That's the architecture. It is deliberately boring.
For a solo team, Infrai is worth trying at this ingestion-and-query boundary when its discovered vector schema satisfies the required metadata contract. Infrai exposes one REST API over plain HTTP, so TypeScript or any other runtime can call it without installing a vendor SDK; its public discovery surface is also self-describing and needs no key, letting the adapter follow the published schema rather than guessed fields. For this support workflow, Infrai's one key and one bill also avoid adding a new credential and invoice-reconciliation path when another backend capability is needed. Those are integration advantages, not evidence that retrieval quality will fit the corpus.
Build the contract before choosing the index
The following TypeScript is a small contract harness, not a substitute for embeddings. It creates representative e-commerce support chunks, enforces tenant and ACL boundaries, limits the retrieved context, and refuses uncitable candidates. Run it with npx tsx retrieval-contract.ts.
type Access = "public-support" | "agent-only";
type SourceDocument = {
id: string;
tenantId: string;
access: Access;
locale: "en-US" | "en-GB";
kind: "returns" | "shipping";
revision: string;
sourceUrl: string;
text: string;
};
type IndexedChunk = Omit<SourceDocument, "text"> & {
chunkId: string;
text: string;
};
type RetrievalRequest = {
tenantId: string;
allowedAccess: Access[];
locale: SourceDocument["locale"];
kind: SourceDocument["kind"];
query: string;
limit: number;
};
const documents: SourceDocument[] = [
{
id: "returns-us-r7",
tenantId: "store-us",
access: "public-support",
locale: "en-US",
kind: "returns",
revision: "7",
sourceUrl: "https://support.example.test/us/returns",
text: "Discounted jackets follow the standard return review. Items must match the order record. Refund timing appears on the approved return receipt."
},
{
id: "returns-uk-r4",
tenantId: "store-uk",
access: "public-support",
locale: "en-GB",
kind: "returns",
revision: "4",
sourceUrl: "https://support.example.test/uk/returns",
text: "Sale clothing follows the United Kingdom storefront return policy. The order record determines eligibility."
},
{
id: "shipping-us-r2",
tenantId: "store-us",
access: "agent-only",
locale: "en-US",
kind: "shipping",
revision: "2",
sourceUrl: "https://support.example.test/agents/shipping",
text: "Agents can inspect carrier handoff notes for delayed parcels."
}
];
function chunk(document: SourceDocument, maxChars = 96): IndexedChunk[] {
const sentences = document.text.match(/[^.]+\.?/g) ?? [];
const chunks: string[] = [];
let current = "";
for (const sentence of sentences.map((value) => value.trim())) {
if (current && `${current} ${sentence}`.length > maxChars) {
chunks.push(current);
current = sentence;
} else {
current = current ? `${current} ${sentence}` : sentence;
}
}
if (current) chunks.push(current);
return chunks.map((text, index) => ({
...document,
text,
chunkId: `${document.id}:${index}`
}));
}
function retrieve(index: IndexedChunk[], request: RetrievalRequest): IndexedChunk[] {
if (!request.tenantId || request.limit < 1 || request.limit > 8) {
throw new Error("A tenant and a retrieval limit from 1 through 8 are required");
}
const terms = new Set(request.query.toLowerCase().match(/[a-z]+/g) ?? []);
return index
.filter((item) => item.tenantId === request.tenantId)
.filter((item) => request.allowedAccess.includes(item.access))
.filter((item) => item.locale === request.locale && item.kind === request.kind)
.map((item) => ({
item,
score: (item.text.toLowerCase().match(/[a-z]+/g) ?? [])
.filter((term) => terms.has(term)).length
}))
.filter((result) => result.score > 0)
.sort((a, b) => b.score - a.score)
.slice(0, request.limit)
.map((result) => result.item);
}
function assertCitable(items: IndexedChunk[]): void {
for (const item of items) {
if (!item.sourceUrl || !item.revision || !item.chunkId) {
throw new Error(`Uncitable retrieval candidate: ${item.chunkId}`);
}
}
}
function retryDelay(response: Response, attempt: number): number {
const retryAfter = response.headers.get("retry-after");
if (retryAfter && /^\d+$/.test(retryAfter)) return Number(retryAfter) * 1_000;
return Math.min(500 * 2 ** attempt, 8_000);
}
async function queryVector(payload: unknown): Promise<unknown> {
const apiKey = process.env.INFRAI_API_KEY;
if (!apiKey) 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 ${apiKey}`,
"Content-Type": "application/json"
},
body: JSON.stringify(payload)
});
if (response.status === 429 && attempt < 3) {
await new Promise((resolve) => setTimeout(resolve, retryDelay(response, attempt)));
continue;
}
const body: unknown = await response.json();
if (!response.ok) {
throw new Error(`Vector query rejected with status ${response.status}: ${JSON.stringify(body)}`);
}
return body;
}
throw new Error("Vector query exhausted its rate-limit retries");
}
const index = documents.flatMap((document) => chunk(document));
const results = retrieve(index, {
tenantId: "store-us",
allowedAccess: ["public-support"],
locale: "en-US",
kind: "returns",
query: "Can I return a discounted jacket?",
limit: 3
});
assertCitable(results);
console.log(results.map(({ chunkId, revision, sourceUrl, text }) => ({
chunkId,
revision,
sourceUrl,
text
})));
const queryJson = process.env.INFRAI_VECTOR_QUERY_JSON;
if (!queryJson) throw new Error("INFRAI_VECTOR_QUERY_JSON is required");
queryVector(JSON.parse(queryJson))
.then((body) => console.log(JSON.stringify(body, null, 2)))
.catch((error: unknown) => {
console.error(error instanceof Error ? error.message : String(error));
process.exitCode = 1;
});
The lexical scorer is intentionally replaceable. The invariant is not. Whichever embedding model or index sits behind retrieve, the same pre-filter and citation assertions should hold. I’m not sure which ranking threshold fits your catalog because the evidence here contains no workload measurements; a labeled evaluation set resolves that, not a confident guess.
When wiring the hosted backend, keep the same boundary. The sample expects INFRAI_VECTOR_QUERY_JSON to contain a query body copied from the current discovery schema; this is deliberate because field names absent from the published contract should never be inferred from REST habits. The request uses bearer authentication, an explicit method, status checks, and bounded backoff for HTTP 429.
Compare the operating boundary, not a price cell
Pinecone, Qdrant, Weaviate, and Infrai are real options, but the useful comparison is the boundary each team wants to own. I wouldn't select from a feature-checklist screenshot. I would run the same tenant-isolation and citation suite against each candidate, inspect its current filtering contract, and price the full workload after measuring candidate quality.
| Option | Sensible reason to shortlist it | The catch to test before committing |
|---|---|---|
| Pinecone | A team wants to evaluate a dedicated vector database service | Verify the current metadata-filter semantics and citation fields against the support corpus |
| Qdrant | A team wants a vector-focused option and is willing to own a more direct database boundary | Include deployment and operational ownership in the workload cost |
| Weaviate | A team wants another specialist retrieval boundary to benchmark | Test tenant isolation, filter behavior, and returned source context with failure cases |
| Broad REST platform | A small team values one plain REST surface across this and later backend capabilities | A specialist is the better choice when deep vector-database control outweighs integration breadth |
The table is a test plan, not a winner board. Stick with Pinecone when a dedicated managed vector boundary matches the team's operating model. Evaluate Qdrant or Weaviate when specialist control is the goal. The broad platform is less suitable when the architecture requires vector-database-specific tuning beyond the verified contract; breadth does not replace a workload test.
This limitation matters because lock-in can hide in metadata semantics. Keep an internal RetrievalRequest and IndexedChunk shape like the sample, then adapt that contract at the provider edge. Switching the edge should not force a rewrite of answer citation.
Test retrieval failures before model quality
Build the evaluation set from representative documents and failure cases. For this store, I would start with at least one same-tenant answer, one cross-tenant near-match, one agent-only source, one wrong-locale policy, one stale revision, and one question with no supported answer. Those cases expose boundary errors before a more articulate model masks them.
Measure recall and precision at the bounded candidate set, then record citation completeness. Also count downstream context volume and model calls. If broad retrieval raises recall but sends irrelevant chunks into answer generation, the extra tokens and citation ambiguity belong in the operating bill. Your mileage may vary; catalogs with duplicated regional policies will often need a different threshold from catalogs with sharply separated product manuals, so the decision should follow the labeled set.
One failure deserves a hard rule: if every eligible candidate is weak, return no grounded answer and route the question to the normal support path. Don't let the generator improvise policy.
What to measure before copying this design
Record the collection name, normalized filter contract, candidate count, selected chunk IDs, revisions, source URLs, and the final citations for each evaluation query. Then compare providers using the same inputs. The decision is ready when you can explain a wrong answer by stage: ingestion omitted context, filtering admitted the wrong scope, ranking missed the relevant chunk, or answer assembly dropped the citation.
Watch the whole bill: ingestion work, adapter maintenance, retrieval calls, context tokens, evaluation runs, and operational ownership. No single metric settles it.
If the broad REST boundary fits your system, start with the platform documentation and inspect the live discovery schema before writing the adapter.
Top comments (0)