Domain 3 β€” Module 1 of 5 20%
27 of 31 overall
Domain 3: Implement AI and analytics capabilities in database solutions Free ⏱ ~24 min read

Vector and Full-Text Retrieval

Configure vector and full-text policies, select flat or DiskANN indexes, scope tenant searches and measure retrieval quality and cost.

Two ways to find a useful document

Full-text search looks at words, using language-aware processing and lexical relevance.

Vector search compares numeric embeddings that represent meaning. It can find related text even when the words differ.

Both can keep the source content, metadata and retrieval representation in the same Cosmos DB item. Neither decides whether the caller is allowed to see the item.

An embedding policy is not an index

Generate document and query embeddings with compatible model settings and preprocessing. Arrays of the same length can still come from incompatible semantic spaces.

Enable the supported account capability, then configure the container’s vector representation:

{
  "vectorEmbeddings": [
    {
      "path": "/embedding",
      "dataType": "float32",
      "dimensions": 1536,
      "distanceFunction": "cosine"
    }
  ]
}

The policy describes the path, element type, dimensions and metric. The indexing policy separately chooses how that path is searched.

Current supported element types include float32, float16, int8 and uint8. A lower-precision representation can save space but may affect quality. Do not change type or dimensions without validating the ingestion and query pipelines.

Select an index using the actual candidate set

TypeSearch characteristicsCurrent maximum dimensions
flatExact search over original vectors505
quantizedFlatScan over compressed vectors; possible accuracy loss4096
diskANNApproximate nearest neighbours optimized for scale4096

A 1,536-dimensional embedding cannot use a flat index simply because the dataset is small.

For quantizedFlat and diskANN, the documentation notes that fewer than 1,000 inserted vectors result in a full scan. A successful query does not prove that the expected indexed path is active.

An illustrative indexing-policy fragment:

{
  "excludedPaths": [
    { "path": "/embedding/*" }
  ],
  "vectorIndexes": [
    { "path": "/embedding", "type": "diskANN" }
  ]
}

This excludes unnecessary ordinary range indexing of the array while retaining its vector index. Keep ordinary indexes needed by actual metadata filters; the fragment is not a complete policy to paste over every production setting.

Query nearby items

SELECT TOP 10 c.id, c.title
FROM c
WHERE c.tenantId = @tenantId
ORDER BY VectorDistance(c.embedding, @queryVector)

The query embedding must match the configured representation. Derive or validate @tenantId from trusted identity.

DiskANN is approximate. Replicas build their vector indexes independently, so repeated queries can show small result or ordering differences. That alone is not proof of corruption.

Increasing searchListSizeMultiplier can improve recall at additional RU and latency cost. Compare that change against judged queries and an appropriate exact baseline.

Data partitioning and vector sharding

The container partition key distributes application data. A vectorIndexShardKey divides a DiskANN index according to a document property.

{
  "vectorIndexes": [
    {
      "path": "/embedding",
      "type": "diskANN",
      "vectorIndexShardKey": ["/tenantId"]
    }
  ]
}

A query filtered to a tenant can search a focused index. This can reduce the candidate set, latency and RU cost.

The vector shard key does not replace the data partition key or the key required for point reads. It also does not authorize an arbitrary caller to select another tenant. Verify the currently supported combination when using hierarchical partition keys.

Configure full-text retrieval

Declare text paths and language in a full-text policy:

{
  "defaultLanguage": "en-US",
  "fullTextPaths": [
    { "path": "/content", "language": "en-US" }
  ]
}

Add a matching fullTextIndexes entry to the container’s indexing policy. An ordinary scalar range index is not equivalent to this specialized text index.

RequirementFunction
A phrase in the propertyFullTextContains
All supplied terms, not necessarily adjacentFullTextContainsAll
At least one supplied termFullTextContainsAny
BM25 relevance orderingFullTextScore in ORDER BY RANK
SELECT TOP 10 c.id, c.title
FROM c
WHERE FullTextContainsAll(c.content, "pump", "repair")
ORDER BY RANK FullTextScore(c.content, "pump", "repair")

Do not project FullTextScore in SELECT or use it as a numeric WHERE predicate; the documented scoring function is for the ranking clause.

Multi-language support has preview and regional considerations. Test the actual languages rather than assuming identical stemming and stop-word behaviour.

Measure the right things

Use real model-generated embeddings, representative filters and realistic dataset sizes. Random vectors are not a useful proof of semantic relevance.

Track:

  • Relevance or recall against judged results.
  • Tail latency rather than average latency alone.
  • RU consumption per request.
  • Write cost and index maintenance.
  • Performance for small and large tenant candidate sets.

If the model changes, regenerate embeddings for the source content into a compatible path or container and validate before switching query traffic. Padding old vectors does not recreate a new model’s representation.

Question

Does equal embedding dimensionality guarantee compatible semantic search?

Click or press Enter to reveal answer

Knowledge Check

A 1,536-dimensional vector collection needs an index. Which statement is correct?

Official references