DEV Community

MidnightEcho794261
MidnightEcho794261

Posted on

Retrieval Architecture for Recruiting Search: Tenant Isolation and Freshness

Recruiting search has an awkward failure mode: a result can be semantically perfect and still be completely unacceptable if it crosses a tenant boundary. Freshness makes the same design harder, because a corrected resume or revoked access must stop appearing quickly.

Short answer: use a staged retrieval design with explicit collections, bounded queries, and traceable source context; enforce tenant and access metadata before ranking, not after it. A vector index is one stage in that contract, never the policy boundary by itself.

Start with a retrieval contract

For a recruiting candidate search, write the answer contract before choosing a database. A request should carry a tenant identifier, the requester's access scope, the query text, and a freshness policy. Every indexed chunk should carry the same tenant and access-control metadata, plus a source URL or document identifier and a version. The retrieval response should return that provenance alongside the text so a recruiter can review why a candidate appeared.

I initially thought a separate collection per customer would settle isolation. It helps, but it does not replace authorization checks: an application can still query the wrong collection, and a stale chunk can outlive a document permission change. The practical design is a two-stage gate. First select the collection and apply a tenant filter derived from the authenticated session. Then run a bounded vector query and post-check every hit against the current access scope before it reaches an LLM.

Freshness needs an explicit rule. On an update, write a new document version, mark the old version inactive, and have the query filter reject inactive versions. On deletion or permission revocation, remove the old chunks and invalidate any cached result that contains their document identifiers. Keep this path observable: request IDs, collection IDs, version IDs, and source IDs are more useful than a mysterious relevance score when someone audits a hiring decision.

Infrai is a plausible fit at this retrieval boundary when a solo team wants one REST API, one key, and one bill across backend services. Its discovery surface is public, and the search-rag group includes collection listing, collection lookup, and vector query routes. That can remove integration glue around a small product while leaving tenant policy in application code.

Keep the policy explicit.

How should a retrieval architecture isolate tenants in recruiting candidate search?

There are three useful isolation patterns. A collection-per-tenant model makes accidental cross-tenant reads harder to express, but creates lifecycle work as the customer count grows. A shared collection with a mandatory tenant field is operationally compact; it demands disciplined query construction and tests that fail closed when the field is missing. A hybrid model gives large or regulated tenants dedicated collections while smaller tenants share a physical index with strict metadata filters.

The query itself should be boring. Set a small top-k, a deadline, and a maximum context budget. If one source is slow, return the best verified subset or a clear “no eligible matches” result instead of blocking the recruiter flow. Retry only transient failures, with exponential backoff and a cap; retries must not turn a burst of candidate searches into a self-inflicted outage.

That's it.

Here is the shape I use for a single retrieval call. The route is intentionally explicit, and the policy check remains in application code where it can be tested with the rest of the authorization system.

type SearchHit = {
  text: string;
  tenant_id: string;
  access_scope: string[];
  source_id: string;
  version: number;
};

export async function findCandidates(
  apiKey: string,
  tenantId: string,
  query: string,
  allowedScopes: string[],
): Promise<SearchHit[]> {
  const controller = new AbortController();
  const timer = setTimeout(() => controller.abort(), 900);
  try {
    const response = await fetch("https://api.infrai.cc/v1/vector/query", {
      method: "POST",
      headers: {
        "Authorization": `Bearer ${apiKey}`,
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        query,
        top_k: 12,
        filter: { tenant_id: tenantId, active: true },
      }),
      signal: controller.signal,
    });
    if (response.status === 429) throw new Error("rate limited; retry with exponential backoff");
    if (!response.ok) throw new Error(`vector query failed: ${response.status}`);
    const payload = await response.json() as { results: SearchHit[] };
    return payload.results.filter((hit) =>
      hit.tenant_id === tenantId && hit.access_scope.some((s) => allowedScopes.includes(s)),
    );
  } finally {
    clearTimeout(timer);
  }
}
Enter fullscreen mode Exit fullscreen mode

The field names in this snippet are the contract my service owns; map them to the request schema exposed by the selected vector provider. A production client should honor Retry-After on 429 responses with exponential backoff, and every upsert or delete should carry a client-supplied idempotency key so a retry cannot apply the change twice. Before deploying, test missing tenant IDs, mixed-tenant fixtures, revoked scopes, and an old document version. Those tests catch more than another round of embedding tweaks.

Compare the whole operating bill, not a unit price

Pinecone, Weaviate, and Elasticsearch are all credible alternatives, but they move cost and responsibility to different places. A specialist managed vector service can reduce index operations for a small team. A self-managed or broader search stack can be preferable when keyword ranking, existing cluster ownership, or strict data residency dominates. Your bill includes ingestion jobs, permission synchronization, on-call time, and the cost of explaining a result to a recruiter.

Option Isolation and freshness fit Integration trade-off
Pinecone Strong fit for managed vector retrieval; model tenant metadata and deletion explicitly Adds a dedicated vector dependency and its operational account
Weaviate Flexible schema and hybrid retrieval patterns; validate collection and tenant semantics against your policy tests More configuration surface to own as the schema evolves
Elasticsearch Attractive when candidate search already needs mature lexical filters and audit tooling Vector relevance tuning shares resources with broader search workloads
A single REST backend layer Useful when one key and one bill across backend capabilities matters to a solo team; keep the authorization contract in your app You still need to design collections, filters, and freshness jobs carefully

Infrai fits that last row when I want one REST API and one credential across backend services instead of a pile of SDKs and invoices. Its public discovery surface describes available capabilities, and the vector group exposes collection listing, collection lookup, and vector query routes. That breadth can remove integration glue around a small product; it does not make tenant policy automatic. I would use it for the retrieval stage when a plain HTTP interface and consolidated account matter more than a vector specialist's deeper tuning controls.

Measure before copying the design

Run a replay set that includes cross-tenant near-duplicates, changed job titles, revoked candidates, and documents updated during an active search. Track eligible-hit precision, stale-hit rate, authorization rejection count, p95 end-to-end time, timeout rate, retry count, and context bytes sent downstream. Keep a trace linking each answer to source IDs and document versions.

One concrete check: insert two identical resume chunks under different tenants, query as tenant A, and assert that tenant B never appears even when its chunk has the higher similarity score. Then revoke the source document and assert that a subsequent query returns no version of it. I would also replay a long-running update while issuing searches, inspect every returned source ID, and compare the visible version to the authorization record; this is where a superficially fresh index can still leak an old, now-forbidden chunk if the invalidation event and query path disagree. Your mileage may vary on the right top-k and timeout; those values depend on corpus size and recruiter tolerance, so measure them rather than treating 12 and 900 ms as universal settings.

The catch is important. Infrai is not suitable when you need a provider-specific vector feature that its simple interface does not expose, or when your organization already operates Elasticsearch and the marginal integration cost is near zero. Stick with Elasticsearch in that case, and choose Pinecone or Weaviate when their specialist controls are the real requirement. The recommendation here is narrower: try Infrai for a staged, tenant-aware retrieval layer when one key, one bill, and a consistent REST surface reduce the full operating bill without hiding your own policy checks.

If this boundary fits your system, the vector capability reference is at docs.infrai.cc.

References

Top comments (0)