Managing Data Quality

1. Validating Vector Data

Example: Validate

import math
def valid(v):
    return (len(v) == DIM
            and all(isinstance(x, float) for x in v)
            and not any(math.isnan(x) or math.isinf(x) for x in v))

2. Detecting Duplicate Vectors

Example: Cosine Threshold

def is_dup(qv, threshold=0.99):
    r = index.query(vector=qv, top_k=1)
    return r["matches"] and r["matches"][0]["score"] >= threshold

3. Handling Missing Embeddings

SourceAction
Embedding API failureRetry with backoff; DLQ on permanent fail
Empty input textSkip; don't upsert

4. Verifying Upsert Success

Example: Verify by Fetch

r = index.upsert(vectors=batch)
ids = [v["id"] for v in batch]
fetched = index.fetch(ids=ids)["vectors"]
assert len(fetched) == len(ids)

5. Auditing Vector Counts

Example: Compare to Source

src = db.count("documents")
idx = index.describe_index_stats()["total_vector_count"]
assert idx == src, f"Drift: {src - idx}"

6. Detecting Data Drift

SignalDetection
Embedding model changeScore distribution shifts
Stale contentTimestamps grow old
Bad upsertsCounts diverge from source

7. Maintaining Data Consistency

Consistency Recipe

  1. Source DB is ground truth.
  2. Use CDC / outbox to enqueue change events.
  3. Worker upserts/deletes in Pinecone idempotently.
  4. Nightly reconcile job compares counts + samples.

8. Cleaning Stale Data

Example: TTL Cleanup

cutoff = int(time.time()) - 90 * 86400
index.delete(filter={"created_at": {"$lt": cutoff}})

9. Implementing Data Validation Pipelines

StageCheck
Pre-embedText non-empty, language detect
Post-embedDim correct, no NaN
Post-upsertFetch sample, verify

10. Monitoring Data Quality Metrics

MetricWhy
% failed embeddingsUpstream issues
Score distributionCatch model drift
Recall@k on eval setRetrieval quality