Fetching Vectors by ID

1. Performing Fetch Operation

Example: Fetch by IDs

res = index.fetch(ids=["doc1", "doc2", "doc3"])
for vid, vec in res["vectors"].items():
    print(vid, vec["values"][:5], vec["metadata"])
ParamDescription
idsList of vector IDs
namespaceSource namespace
Max IDs1000 per call

2. Fetching from Namespace

Example: Namespaced Fetch

res = index.fetch(ids=["u1", "u2"], namespace="users")
BehaviorDetail
Wrong namespaceReturns empty
Default""

3. Fetching Multiple Vectors

PatternNote
Up to 1000 IDsSingle fetch call
> 1000Batch into chunks

4. Validating Fetch Results

Example: Missing IDs

requested = {"a", "b", "c"}
returned = set(res["vectors"].keys())
missing = requested - returned
FieldMeaning
vectorsDict keyed by ID; only existing IDs included
namespaceNamespace queried

5. Handling Missing Vectors

ReasonAction
Not yet upsertedRetry after consistency delay
DeletedConfirm via audit log
Wrong namespaceVerify namespace parameter

6. Handling Fetch Errors

ErrorCause
400Invalid ID format
404Index not found
429Rate limit

7. Optimizing Fetch Performance

TipEffect
Batch IDsOne round-trip per 1000
Skip if cached locallyAvoid unnecessary calls
Async parallel batchesHigher throughput

8. Using Fetch for Data Validation

Example: Verify After Upsert

index.upsert(vectors=batch)
sample = [v["id"] for v in batch[:5]]
got = index.fetch(ids=sample)
assert len(got["vectors"]) == len(sample)

9. Implementing Batch Fetch Patterns

Example: Chunked Fetch

all_vecs = {}
for i in range(0, len(ids), 1000):
    chunk = ids[i:i+1000]
    res = index.fetch(ids=chunk)
    all_vecs.update(res["vectors"])

10. Comparing Fetch vs Query

fetch()

  • Lookup by exact ID
  • No similarity computation
  • Returns values + metadata
  • Use: known IDs, data validation

query()

  • Similarity search by vector or ID
  • Ranks by metric score
  • Supports filters, top_k
  • Use: discovery / retrieval
Aspectfetchquery
LatencyLowHigher (ANN search)
FilteringNoYes