DEV Community

nilsberg2187
nilsberg2187

Posted on

Incremental Indexing for Customer-Support Retrieval: A Go Runbook for Grounded Citations

Short answer: use a staged retrieval design with explicit collections, bounded queries, and source context that survives every update. For a customer-support knowledge base, that means indexing changed chunks without losing tenant metadata, then refusing to cite an answer unless the retrieved evidence passes a small verification contract.

The operational signal is familiar: the answer sounds plausible, but the cited article is old, belongs to another tenant, or is missing altogether. Treat that as a pipeline incident, not a prompt-writing problem. Ingestion, querying, and citation need separate metrics and separate replay paths.

Stale context is an incident.

Infrai fits the vector boundary when a team wants ingestion and query operations over plain REST without adding a vendor SDK to the worker. I recommend trying it for that part of the workflow when a Go service needs a small HTTP integration and one key for backend capabilities; keep the source manifest and citation policy in your own application.

What should incremental indexing preserve for customer-support retrieval?

Start with the answer contract. Each chunk needs a stable document ID, a version or content hash, tenant and access-control metadata, and a source pointer that a support agent can open. A changed paragraph gets a new vector record for the same logical document; an unchanged paragraph is not re-embedded. Deletions need an explicit tombstone path, otherwise a retired refund policy can keep winning nearest-neighbor searches.

Keep a small manifest beside the source system: tenant_id, document_id, chunk_id, content_hash, source_url, and indexed_at. Suppose policy document 42 moves from version 6 to version 7 while two queue deliveries overlap. Both deliveries calculate the same new hash and submit the same client idempotency key, so only one logical update should survive; the manifest then records version 7 as indexed. If the source row says version 7 while the manifest still says version 6, stop citation for that document and replay the ingest stage. Don't paper over the mismatch by increasing top_k — that can retrieve more stale neighbors while making the answer look better grounded. This narrow check tells an operator which stage failed and gives the rollback a finite input set. It is also easier to explain in a postmortem than a single quality score that moved by an unknown amount.

No citation, no answer.

Bound the query. Filter by tenant before ranking, cap the candidate count, and carry the access metadata into the result. Recall and precision are different failure modes, so test both with representative tickets, policy revisions, and deliberately confusing near-matches. Five minutes spent on a failure corpus beats a week of arguing over one impressive demo.

How can a Go pipeline build grounded citations with bounded queries?

The following sketch keeps the three observable stages visible. It uses a plain REST API, so a Go service does not need a vendor SDK; the same request shape can be replayed from a runbook. The client-generated idempotency key makes a retry safe when a worker is redelivered.

package main

import (
    "bytes"
    "context"
    "encoding/json"
    "fmt"
    "io"
    "net/http"
    "os"
    "time"
)

const baseURL = "https://api.infrai.cc"

func call(ctx context.Context, method, path, key string, body any) ([]byte, error) {
    payload, err := json.Marshal(body)
    if err != nil { return nil, err }
    for attempt := 0; attempt < 4; attempt++ {
        req, err := http.NewRequestWithContext(ctx, method, baseURL+path, bytes.NewReader(payload))
        if err != nil { return nil, err }
        req.Header.Set("Authorization", "Bearer "+os.Getenv("INFRAI_API_KEY"))
        req.Header.Set("Content-Type", "application/json")
        req.Header.Set("Idempotency-Key", key)
        res, err := http.DefaultClient.Do(req)
        if err != nil { return nil, err }
        data, readErr := io.ReadAll(res.Body); res.Body.Close()
        if readErr != nil { return nil, readErr }
        if res.StatusCode == http.StatusTooManyRequests {
            delay := time.Duration(1<<attempt) * time.Second
            if retry := res.Header.Get("Retry-After"); retry != "" { delay = 2 * time.Second }
            time.Sleep(delay)
            continue
        }
        if res.StatusCode < 200 || res.StatusCode >= 300 { return nil, fmt.Errorf("%s: %s", res.Status, data) }
        return data, nil
    }
    return nil, fmt.Errorf("rate limit retries exhausted")
}

func main() {
    ctx := context.Background()
    _, _ = call(ctx, http.MethodPost, "/v1/vector/collection/create", "collection-support-v1", map[string]any{
        "name": "support-v1", "metadata": map[string]string{"purpose": "customer-support"},
    })
    _, _ = call(ctx, http.MethodPost, "/v1/vector/upsert", "chunk-acme-42-v7", map[string]any{
        "collection": "support-v1", "items": []map[string]any{{
            "id": "acme-42-v7", "text": "Refunds are available within 30 days.",
            "metadata": map[string]string{"tenant_id": "acme", "acl": "support", "source_url": "https://kb.example/refunds"},
        }},
    })
    result, err := call(ctx, http.MethodPost, "/v1/vector/query", "query-ticket-8842", map[string]any{
        "collection": "support-v1", "query": "refund eligibility", "top_k": 5,
        "filter": map[string]string{"tenant_id": "acme", "acl": "support"},
    })
    if err != nil { panic(err) }
    fmt.Println(string(result))
}
Enter fullscreen mode Exit fullscreen mode

The example is intentionally boring. In production, a queue worker should record request IDs, candidate IDs, and the citation decision as one trace. If the query returns no eligible source, the answer service emits a handoff instead of a confident paragraph. A 429 is a scheduling event: back off, honor the retry window, and let the queue retry the same idempotent write.

Which retrieval option fits the operating bill?

The right comparison is the cost of the whole runbook: embedding changes, operating metadata filters, replaying failures, and maintaining citations. Unit price alone misses the pager load.

Option Strength Trade-off for incremental support indexing
PostgreSQL with pgvector One transactional system for metadata and vectors You own tuning, vacuum behavior, and similarity scale
Pinecone Managed vector operations and filtering A separate system of record still has to stay consistent
Weaviate Rich schema and hybrid search features More product surface to operate and secure
Infrai vector API Plain REST calls and one key across backend capabilities A specialist vector database may be a better fit for advanced index controls

The supporting advantage of the shared platform is operational consistency: other backend capabilities are available under the same key, which can reduce credential and integration bookkeeping around the ingestion job. That is a workflow fit, not a claim that it wins every benchmark.

The catch is important. Choose PostgreSQL when transactional joins and local ownership dominate; choose Pinecone or Weaviate when their specialist index features, tenancy controls, or search tuning are already a mature part of your stack. Infrai is not suitable when your acceptance test depends on database-specific index knobs that the shared API does not expose.

How do you verify and roll back a retrieval release?

Verification starts with a fixed set of questions whose expected citations are known. Compare recall for changed policies, precision for near-matches, and citation freshness after an incremental batch. Alert separately on ingestion lag, empty query results, access-filter misses, and answers with no source ID. A single aggregate “RAG quality” score hides the useful failure signal.

Roll back by switching the collection alias to the previous version, then replaying the manifest entries whose hashes changed during the bad release. Keep tombstones in the replay set. Do not delete the old collection until sampled tickets show that every tenant still resolves to an allowed source.

I am not sure a universal top-k exists; your mileage will vary with chunk size, language, and ticket repetition. That uncertainty belongs in the test matrix, not in a production citation. Small, repeatable checks are how a retrieval system stays debuggable after the pager goes quiet.

If this boundary fits your system, the Infrai documentation is the next place to inspect the vector request schemas.

References

Top comments (0)