Month: August 2026

Choose between using ANN and ENN for vector search (DP-800 Exam Prep)

This post is a part of the DP-800: Developing AI-Enabled Database Solutions Exam Prep Hub.
This topic falls under these sections:
Implement AI capabilities in database solutions (25–30%)
   --> Design and implement intelligent search
      --> Choose between using ANN and ENN for vector search


Note that there are 10 practice questions (with answers) at the end of each section to help you solidify your knowledge of the material. Also, there are 4 practice tests with 30 questions each available from the hub's main page below the exam topics section.

Introduction

Vector search is the foundation of modern AI-powered applications such as Retrieval-Augmented Generation (RAG), semantic search, recommendation engines, document similarity, and intelligent assistants. As vector databases grow from thousands to millions of embeddings, selecting the appropriate search algorithm becomes increasingly important.

One of the most important architectural decisions is choosing between:

  • Approximate Nearest Neighbor (ANN) search
  • Exact Nearest Neighbor (ENN) search

Although both methods retrieve vectors that are similar to a query vector, they differ significantly in performance, scalability, accuracy, resource usage, and appropriate use cases.

For the DP-800 exam, candidates should understand when to use ANN versus ENN, how vector indexes influence each approach, and the trade-offs involved in balancing search speed with search accuracy.


Understanding Nearest Neighbor Search

Once embeddings have been generated for documents, products, images, or other data, a user query is also converted into an embedding.

The search engine must identify the vectors that are “closest” to the query vector.

Closeness is typically measured using:

  • Cosine similarity
  • Euclidean distance (L2)
  • Dot product

The challenge becomes finding the nearest vectors efficiently.

If a database contains:

  • 5,000 vectors
  • 500,000 vectors
  • 50 million vectors

the search strategy dramatically affects response time.


Exact Nearest Neighbor (ENN)

Exact Nearest Neighbor performs an exhaustive comparison.

Every stored vector is compared against the query vector.

The system computes the distance to every record before returning the closest matches.

Characteristics

  • Searches every vector
  • Produces mathematically exact results
  • No approximation
  • Highest accuracy
  • Computationally expensive
  • Slower as data grows

ENN Workflow

Query Vector
Compare against Vector 1
Compare against Vector 2
Compare against Vector 3
...
Compare against Vector N
Sort by similarity
Return Top K

Advantages of ENN

Maximum Accuracy

Every possible vector is evaluated.

No relevant documents are skipped.


Deterministic Results

The same query always produces the same ranking.


No Index Approximation

Results represent the actual nearest neighbors.


Simpler Conceptually

The algorithm is straightforward.

No graph traversal or approximation heuristics are involved.


Disadvantages of ENN

Poor Scalability

Performance decreases linearly with dataset size.

Examples:

  • 1,000 vectors → very fast
  • 100,000 vectors → acceptable
  • 10 million vectors → slow
  • 100 million vectors → often impractical

High CPU Usage

Every query compares against every stored embedding.


Higher Latency

Search time increases as the vector collection grows.


Common ENN Use Cases

ENN is appropriate when:

  • Maximum precision is required
  • Dataset is relatively small
  • Scientific applications require exact matches
  • Benchmarking ANN algorithms
  • Testing search quality
  • Evaluation environments

Examples include:

  • Medical research
  • Financial analytics
  • Legal document comparison
  • Academic datasets
  • Quality assurance testing

Approximate Nearest Neighbor (ANN)

Approximate Nearest Neighbor avoids comparing every vector.

Instead, it uses specialized vector indexes that intelligently narrow the search space.

The goal is to find vectors that are almost certainly among the nearest neighbors while dramatically improving search speed.

ANN typically achieves:

  • 95–99.9% recall
  • Much lower latency
  • Massive scalability

ANN Workflow

Query Vector
Search Vector Index
Explore Nearby Candidates
Evaluate Candidate Vectors
Return Top K

Instead of examining millions of vectors, ANN may evaluate only a few hundred or a few thousand candidate vectors.


Advantages of ANN

Extremely Fast

ANN dramatically reduces search time.

Milliseconds instead of seconds.


Highly Scalable

Suitable for:

  • Millions of vectors
  • Tens of millions
  • Hundreds of millions
  • Billions of vectors

Lower Compute Costs

Fewer distance calculations are required.


Excellent User Experience

Ideal for interactive AI applications requiring real-time responses.


Production Ready

Nearly every modern AI search engine uses ANN.

Examples include:

  • Azure AI Search
  • Azure SQL vector indexes
  • Azure Cosmos DB vector search
  • Pinecone
  • Milvus
  • Weaviate
  • Qdrant
  • FAISS
  • pgvector with ANN indexes

Disadvantages of ANN

Results Are Approximate

Occasionally, the true nearest neighbor may not be returned.

Instead, the algorithm returns vectors that are extremely close.


Slight Reduction in Recall

Typical recall values:

  • 95%
  • 98%
  • 99%

depending on index configuration.


Index Maintenance

ANN requires building and maintaining vector indexes.


Additional Memory Usage

Indexes consume additional storage.


ANN vs ENN Comparison

FeatureENNANN
Accuracy100%Nearly 100%
SpeedSlowerMuch faster
ScalabilityPoorExcellent
Uses Vector IndexNoYes
CPU UsageHighLower
Memory UsageLowerHigher
Best for Small DataYesSometimes
Best for Large DataNoYes
Typical Production ChoiceRareVery Common

Why ANN Is Usually Preferred

Most enterprise AI applications prioritize:

  • Fast responses
  • Interactive user experiences
  • Large knowledge bases
  • Millions of documents

Waiting several seconds for every search is unacceptable.

Therefore, ANN has become the industry standard for production semantic search.

For example:

A chatbot searching:

  • 8 million support articles

cannot realistically compare every embedding.

Instead, ANN rapidly narrows the candidate set before computing exact similarity among only the most promising vectors.


Recall vs Accuracy

One of the most important concepts is recall.

Recall measures how many of the true nearest neighbors are successfully returned.

Example:

Suppose the true Top 10 neighbors are:

A
B
C
D
E
F
G
H
I
J

An ANN search returns:

A
B
C
D
E
F
G
H
I
K

Recall is:

9 / 10 = 90%

Although one neighbor is missing, the results are still highly useful for most AI applications.

Many ANN algorithms achieve recall rates above 99%.


Popular ANN Algorithms

Several indexing algorithms support ANN search.

Common examples include:

HNSW (Hierarchical Navigable Small World)

Most common modern ANN algorithm.

Advantages:

  • Very fast
  • Excellent recall
  • High-quality results
  • Widely used

IVF (Inverted File Index)

Partitions vectors into clusters.

Search examines only relevant clusters.

Good for extremely large datasets.


DiskANN

Optimized for very large vector collections stored partly on disk.

Designed for cloud-scale systems.


Product Quantization (PQ)

Compresses vectors to reduce memory usage.

Often combined with IVF.


Choosing Between ANN and ENN

Choose ENN When

  • Dataset is small
  • Exact results are mandatory
  • Benchmarking search quality
  • Scientific analysis
  • Compliance requires deterministic behavior
  • Testing vector models

Choose ANN When

  • Dataset contains millions of vectors
  • Response time matters
  • Building chatbots
  • Implementing RAG
  • Semantic document search
  • Recommendation systems
  • AI copilots
  • Enterprise knowledge bases

ANN in Azure SQL

Azure SQL’s vector search capabilities are designed to support scalable semantic search workloads.

When vector indexes are implemented, Azure SQL can perform ANN searches efficiently, making it practical to query very large embedding collections while maintaining excellent recall.

This enables AI-powered applications to combine:

  • Relational filtering
  • Vector similarity
  • SQL queries
  • AI inference

within a single database platform.


ANN and Hybrid Search

Many production applications combine ANN with traditional filtering.

Example:

A company stores:

  • 20 million product embeddings

A customer searches:

“Wireless ergonomic keyboard”

The query first filters:

Category = Electronics
Brand = Microsoft
Price < $150

Then ANN searches only the filtered candidate vectors.

This combination improves:

  • Speed
  • Relevance
  • Scalability

DP-800 Exam Tips

  • Understand that ENN performs exhaustive comparisons, while ANN uses vector indexes to accelerate nearest-neighbor retrieval.
  • Remember that ANN trades a small amount of accuracy for significant gains in performance and scalability, making it the preferred option for production AI systems.
  • Be familiar with HNSW, IVF, and other ANN indexing techniques at a conceptual level.
  • Know that ENN is appropriate for small datasets, benchmarking, and scenarios requiring mathematically exact results.
  • Expect scenario-based questions asking which approach is best based on dataset size, latency requirements, scalability, and accuracy expectations.
  • Recognize that ANN is the default choice for RAG systems, semantic search, recommendation engines, AI assistants, and enterprise knowledge bases containing millions of embeddings.

Practice Exam Questions


Question 1

A company has built a Retrieval-Augmented Generation (RAG) solution that searches through 50 million document embeddings. Users expect responses within two seconds. Which vector search approach is the most appropriate?

A. Exact Nearest Neighbor (ENN) because it guarantees mathematically exact results for every query

B. Approximate Nearest Neighbor (ANN) because it provides low-latency searches while maintaining high recall

C. Sequential table scans because they avoid maintaining vector indexes

D. Full-text search because embeddings are not required for semantic search

Correct Answer: B

Explanation: ANN is specifically designed for large-scale vector datasets where fast response times are essential. It dramatically reduces search latency while maintaining very high recall, making it ideal for production RAG systems.


Question 2

A research laboratory is validating a new embedding model and requires every query to return the mathematically closest vectors with no approximation. Which search method should be used?

A. Hybrid search

B. Hierarchical Navigable Small World (HNSW)

C. Exact Nearest Neighbor (ENN)

D. Approximate Nearest Neighbor (ANN)

Correct Answer: C

Explanation: ENN compares the query vector against every stored vector, guaranteeing exact nearest-neighbor results. This makes it appropriate for benchmarking, scientific validation, and testing.


Question 3

What is the primary advantage of Approximate Nearest Neighbor (ANN) search over Exact Nearest Neighbor (ENN) search?

A. ANN always returns more accurate results.

B. ANN eliminates the need for vector embeddings.

C. ANN significantly improves search performance and scalability by reducing the number of vectors evaluated.

D. ANN only works with relational databases.

Correct Answer: C

Explanation: ANN achieves much faster searches by using specialized vector indexes to evaluate only the most promising candidate vectors instead of comparing every vector.


Question 4

A database contains approximately 2,500 embeddings used by a legal review application where accuracy is more important than response time. Which search strategy is most appropriate?

A. Approximate Nearest Neighbor (ANN)

B. Hybrid search

C. Semantic ranking

D. Exact Nearest Neighbor (ENN)

Correct Answer: D

Explanation: With a relatively small dataset and strict accuracy requirements, ENN is preferred because it guarantees exact nearest-neighbor results.


Question 5

Which statement best describes the concept of recall in Approximate Nearest Neighbor search?

A. It measures how quickly a query completes.

B. It measures the percentage of true nearest neighbors successfully returned.

C. It measures the amount of memory consumed by the vector index.

D. It measures the total number of vectors stored.

Correct Answer: B

Explanation: Recall measures how many of the actual nearest neighbors are retrieved by the ANN algorithm. Higher recall indicates results that more closely match those of an exact search.


Question 6

Which indexing algorithm is most commonly associated with modern ANN implementations due to its excellent balance of speed and recall?

A. HNSW (Hierarchical Navigable Small World)

B. B-tree

C. Hash index

D. Clustered columnstore index

Correct Answer: A

Explanation: HNSW is one of the most widely used ANN algorithms because it provides fast searches with excellent recall for large vector datasets.


Question 7

A development team notices that vector search performance decreases as the database grows from thousands to tens of millions of embeddings. Which architectural change is most likely to improve scalability?

A. Replace vector embeddings with keyword indexes.

B. Use ENN for every query.

C. Disable vector indexes.

D. Implement ANN with an appropriate vector index.

Correct Answer: D

Explanation: ANN combined with vector indexes is specifically designed to scale efficiently to millions or even billions of embeddings while maintaining acceptable accuracy.


Question 8

Which characteristic is typically associated with Exact Nearest Neighbor (ENN) search?

A. Uses approximation techniques to improve performance.

B. Compares only a subset of candidate vectors.

C. Performs exhaustive comparisons against every stored vector.

D. Requires HNSW indexing.

Correct Answer: C

Explanation: ENN performs a complete comparison against all stored vectors, ensuring mathematically exact results but requiring significantly more computation.


Question 9

An AI-powered product recommendation system serves millions of users each day. The recommendation engine must respond in milliseconds while maintaining highly relevant results. Which approach best meets these requirements?

A. Exact Nearest Neighbor (ENN)

B. Sequential vector scans

C. ANN using vector indexes

D. Full-table scans followed by sorting

Correct Answer: C

Explanation: ANN is optimized for production AI workloads that require low latency and high scalability while maintaining high-quality semantic search results.


Question 10

Which statement best summarizes the trade-off between ANN and ENN?

A. ENN sacrifices accuracy for better scalability.

B. ANN always returns identical results to ENN.

C. ENN requires vector indexes while ANN does not.

D. ANN slightly reduces accuracy in exchange for dramatically improved search performance and scalability.

Correct Answer: D

Explanation: The primary trade-off is that ANN accepts a small reduction in accuracy (typically maintaining 95–99%+ recall) to achieve significantly faster query performance and support very large datasets.


Go to the DP-800 Exam Prep Hub main page

Evaluate vector index types and metrics (DP-800 Exam Prep)

This post is a part of the DP-800: Developing AI-Enabled Database Solutions Exam Prep Hub.
This topic falls under these sections:
Implement AI capabilities in database solutions (25–30%)
   --> Design and implement intelligent search
      --> Evaluate vector index types and metrics


Note that there are 10 practice questions (with answers) at the end of each section to help you solidify your knowledge of the material. Also, there are 4 practice tests with 30 questions each available from the hub's main page below the exam topics section.

Introduction

Understanding vector indexes and similarity metrics is essential when building AI-enabled database applications that perform semantic search, retrieval-augmented generation (RAG), recommendation engines, and AI-powered document retrieval. Selecting the correct vector index type and similarity metric has a major impact on search accuracy, scalability, latency, and infrastructure costs.

Traditional database indexes are designed to efficiently locate exact values or values within a range.

Examples include:

  • Primary key indexes
  • Clustered indexes
  • Nonclustered indexes
  • Full-text indexes

These indexes perform extremely well for queries such as:

WHERE CustomerID = 123

or

WHERE LastName LIKE 'Smith%'

However, AI applications frequently need to answer questions based on meaning rather than exact text.

For example:

User query:

“Hotels close to the beach with great seafood.”

Documents may contain:

“Oceanfront resort featuring fresh local cuisine.”

There are no matching keywords, yet both sentences describe the same concept.

This is where vector search becomes essential.


What Is a Vector?

A vector is a numerical representation of text, images, audio, or other data generated by an embedding model.

Instead of storing text as characters, AI models convert information into hundreds or thousands of numeric dimensions.

Example:

"The cat sat on the mat."
[0.183,
-0.442,
0.913,
...
1536 dimensions]

Documents discussing similar concepts produce vectors that are mathematically close together.


Why Vector Indexes Are Needed

Suppose a database contains 10 million document embeddings.

Without an index:

  • every query compares against every vector
  • search complexity becomes enormous
  • latency may reach several seconds

Vector indexes organize vectors to reduce the number of comparisons dramatically while preserving high search quality.


Exact vs Approximate Search

Vector search generally falls into two categories.

Exact Search

Also known as:

  • Brute-force search
  • Exhaustive search

Process:

  1. Compare query vector to every stored vector.
  2. Calculate similarity score.
  3. Sort results.
  4. Return best matches.

Advantages:

  • 100% accurate
  • Always finds nearest neighbor
  • Simple implementation

Disadvantages:

  • Slow
  • Poor scalability
  • High CPU usage

Best for:

  • Small datasets
  • Testing
  • Benchmarking

Approximate Nearest Neighbor (ANN)

ANN algorithms search intelligently instead of comparing every vector.

Advantages:

  • Extremely fast
  • Scales to millions or billions of vectors
  • Lower resource consumption

Tradeoff:

  • Results are extremely close to optimal but not always mathematically perfect.

Most enterprise AI systems use ANN indexes.


Common Vector Index Types

1. Flat Index (Brute Force)

Every vector is scanned.

Query
Compare with Vector 1
Compare with Vector 2
Compare with Vector 3
...
Best Match

Advantages

  • Perfect accuracy
  • No preprocessing
  • Easy to maintain

Disadvantages

  • Slow
  • Doesn’t scale well

Best for

  • Small datasets
  • Testing

2. HNSW (Hierarchical Navigable Small World)

One of the most popular ANN indexes.

Rather than checking every vector, HNSW creates multiple graph layers.

High-level layers:

A
B
C

Lower layers:

A — D — E — F
\ |
G — H

The search begins at higher levels and progressively narrows the search.

Advantages

  • Extremely high recall
  • Very low latency
  • Excellent scalability

Disadvantages

  • More memory required
  • Longer index creation time

Commonly used in:

  • Azure SQL vector search
  • AI search engines
  • Modern vector databases

3. IVF (Inverted File Index)

Vectors are grouped into clusters.

Cluster A
Cluster B
Cluster C
Cluster D

Instead of searching every cluster:

  1. Identify closest cluster.
  2. Search only that cluster.

Advantages

  • Very fast
  • Efficient memory usage

Disadvantages

  • Search quality depends on clustering accuracy.

4. Product Quantization (PQ)

PQ compresses vectors into compact representations.

Instead of storing:

1536 floating-point numbers

it stores compressed codes.

Advantages

  • Huge storage savings
  • Faster searches
  • Lower memory usage

Disadvantages

  • Slight loss of precision

Often combined with IVF.


5. Disk-Based Indexes

Some systems keep indexes primarily on disk instead of RAM.

Advantages

  • Supports enormous datasets

Disadvantages

  • Higher latency

Useful when memory is limited.


Comparing Index Types

IndexAccuracySpeedMemoryTypical Use
FlatHighestSlowMediumSmall datasets
HNSWVery HighVery FastHighEnterprise RAG
IVFHighFastMediumLarge datasets
IVF + PQModerate-HighVery FastLowMassive collections
Disk-basedHighModerateLow RAMVery large databases

Understanding Similarity Metrics

A vector index determines how vectors are organized.

A similarity metric determines how closeness is measured.

Choosing the wrong metric can significantly reduce search quality.


Cosine Similarity

The most widely used similarity metric.

Measures the angle between vectors.

Formula (conceptually):

Similarity = cos(angle)

Identical direction:

1.0

Perpendicular:

0

Opposite direction:

-1

Advantages

  • Ignores vector magnitude
  • Excellent for semantic search
  • Very common in embedding models

Typical uses

  • Document search
  • Chatbots
  • RAG
  • Azure OpenAI embeddings

Euclidean Distance

Measures straight-line distance.

Distance = √((x₂−x₁)²...)

Smaller distance means greater similarity.

Advantages

  • Easy to understand
  • Works well for spatial data

Disadvantages

  • Sensitive to vector magnitude

Dot Product

Calculates the mathematical product of vectors.

Useful when embedding magnitude carries meaning.

Often used by recommendation systems.

Advantages

  • Computationally efficient
  • Good with normalized embeddings

Manhattan Distance

Also called:

L1 distance

Measures movement along axes.

|x1-x2| + |y1-y2|

Less common in vector databases.


Hamming Distance

Used for binary vectors.

Measures the number of differing bits.

Common in binary embeddings.


Choosing the Right Similarity Metric

MetricBest For
Cosine SimilaritySemantic search
Euclidean DistanceSpatial similarity
Dot ProductRecommendation systems
Manhattan DistanceGrid-based comparisons
Hamming DistanceBinary vectors

Matching Metrics to Embedding Models

Many embedding models are trained assuming a particular similarity metric.

Examples:

  • OpenAI embeddings → Cosine similarity
  • Azure OpenAI embeddings → Cosine similarity
  • Sentence Transformer models → Cosine similarity (commonly)
  • Some recommendation models → Dot product

Using the incorrect metric can reduce retrieval quality.


Tradeoffs When Evaluating Vector Indexes

Database developers evaluate multiple characteristics.

Search Accuracy

Higher recall produces better retrieval quality.

Higher accuracy often requires:

  • more memory
  • more CPU
  • larger indexes

Query Latency

AI chat applications typically require responses within milliseconds.

Approximate indexes dramatically reduce latency.


Recall

Recall measures how many true nearest neighbors are returned.

Example:

Actual nearest neighbors:

A
B
C
D
E

Returned:

A
B
C
X
Y

Recall:

3/5 = 60%

Higher recall improves RAG quality.


Memory Usage

HNSW indexes often consume substantial memory.

Compressed indexes require much less.


Build Time

Some indexes build quickly.

Others may require extensive preprocessing.

Large enterprise indexes may take hours to create.


Update Performance

Questions to evaluate:

  • How quickly can vectors be inserted?
  • Can vectors be deleted efficiently?
  • Is index rebuilding required?

Applications with frequent updates may favor indexes that support incremental maintenance.


Vector Index Selection Guidelines

Small Collections (<100K vectors)

Recommended:

  • Flat index

Reason:

  • Simplicity
  • Maximum accuracy

Medium Collections (100K–10M)

Recommended:

  • HNSW

Reason:

  • Excellent speed
  • Excellent recall

Massive Collections (100M+)

Recommended:

  • IVF
  • IVF + PQ

Reason:

  • Reduced storage
  • Excellent scalability

Memory-Constrained Systems

Recommended:

  • Product Quantization
  • Disk-based indexes

Vector Indexes in SQL-Based AI Solutions

Modern SQL platforms increasingly support vector capabilities.

Examples include:

  • SQL databases with vector data types
  • Vector indexes
  • Embedding storage
  • Similarity search functions

These capabilities enable developers to combine structured SQL queries with semantic AI search within a single database solution.


Best Practices

  • Match the similarity metric to the embedding model.
  • Use cosine similarity for most semantic search workloads.
  • Prefer ANN indexes for production systems.
  • Benchmark recall, latency, and throughput before deployment.
  • Monitor index performance as datasets grow.
  • Rebuild or optimize indexes when fragmentation or large-scale updates reduce efficiency.
  • Evaluate memory consumption alongside query performance.
  • Test retrieval quality using realistic user queries.

DP-800 Exam Tips

Remember these key points for the exam:

  • Vector indexes optimize similarity search rather than exact matching.
  • ANN indexes trade a small amount of accuracy for significant performance gains.
  • HNSW is a leading ANN algorithm due to its high recall and low latency.
  • IVF clusters vectors before searching.
  • Product Quantization reduces storage requirements.
  • Cosine similarity is the preferred metric for most semantic search scenarios.
  • Choosing the appropriate similarity metric is just as important as choosing the index type.
  • Retrieval quality depends on embeddings, similarity metrics, and index configuration working together.

Practice Exam Questions

Question 1

A development team is building a Retrieval-Augmented Generation (RAG) solution containing over 15 million document embeddings. The application requires low query latency while maintaining high retrieval accuracy.

Which vector index type is the most appropriate?

A. Flat index

B. HNSW

C. Clustered index

D. Full-text index

Answer: B

Explanation:
HNSW is designed for Approximate Nearest Neighbor (ANN) search and offers excellent recall with very low latency, making it a common choice for large-scale RAG implementations. Flat indexes become too slow at this scale, while clustered and full-text indexes are not vector indexes.


Question 2

Which similarity metric is most commonly used with modern text embedding models for semantic search?

A. Manhattan Distance

B. Euclidean Distance

C. Cosine Similarity

D. Hamming Distance

Answer: C

Explanation:
Cosine similarity compares the angle between vectors rather than their magnitude, making it ideal for semantic search. Many embedding models, including Azure OpenAI embeddings, are designed to work effectively with cosine similarity.


Question 3

A database developer wants mathematically perfect nearest-neighbor results regardless of execution time.

Which search method should be selected?

A. Approximate Nearest Neighbor

B. Product Quantization

C. Exhaustive (Flat) Search

D. IVF

Answer: C

Explanation:
Exhaustive or flat search compares the query against every stored vector, guaranteeing the exact nearest neighbors. This approach is computationally expensive but provides maximum accuracy.


Question 4

What is the primary purpose of Product Quantization (PQ)?

A. Improve SQL joins

B. Increase transaction throughput

C. Normalize embeddings

D. Reduce storage and memory requirements

Answer: D

Explanation:
Product Quantization compresses vectors into compact representations, reducing storage and memory usage while enabling efficient searches. The tradeoff is a small reduction in precision.


Question 5

Which statement best describes Approximate Nearest Neighbor (ANN) indexing?

A. It guarantees perfect search accuracy.

B. It searches every vector sequentially.

C. It balances retrieval accuracy with search performance.

D. It only supports binary vectors.

Answer: C

Explanation:
ANN algorithms reduce search time by avoiding exhaustive comparisons. They provide high-quality results with much better performance than exact search, making them suitable for production AI systems.


Question 6

A team notices that their semantic search results have degraded after switching from cosine similarity to Euclidean distance while using the same embedding model.

What is the most likely cause?

A. The embedding model was trained assuming cosine similarity.

B. Euclidean distance always produces identical results.

C. Vector indexes require clustered tables.

D. SQL Server does not support vectors.

Answer: A

Explanation:
Embedding models are often optimized for specific similarity metrics. Using a different metric than the one assumed during training can reduce retrieval quality even if the vectors themselves remain unchanged.


Question 7

Why do vector indexes improve search performance?

A. They reduce the dimensionality of every embedding.

B. They organize vectors so fewer comparisons are needed.

C. They convert vectors into relational tables.

D. They eliminate the need for embeddings.

Answer: B

Explanation:
Vector indexes structure embeddings so that searches examine only promising candidates instead of every stored vector, significantly reducing query latency.


Question 8

A company has a small proof-of-concept application containing 25,000 document embeddings. Search accuracy is more important than performance.

Which index is the best choice?

A. IVF + PQ

B. HNSW

C. Flat index

D. Disk-based ANN index

Answer: C

Explanation:
For relatively small datasets where absolute accuracy is the priority, a flat index is often the simplest and most accurate solution. Performance remains acceptable because the collection size is limited.


Question 9

Which evaluation metric indicates how many true nearest neighbors are successfully returned during a vector search?

A. Latency

B. Precision

C. Throughput

D. Recall

Answer: D

Explanation:
Recall measures the proportion of actual nearest neighbors that are retrieved by the search algorithm. Higher recall generally leads to better retrieval quality in semantic search and RAG systems.


Question 10

When evaluating different vector index types for a production AI solution, which combination of factors is most important?

A. File size and backup frequency

B. Number of SQL tables and views

C. Search latency, recall, memory usage, and index maintenance

D. Number of stored procedures and triggers

Answer: C

Explanation:
Production vector indexes should be evaluated based on their ability to deliver fast queries, high recall, efficient memory utilization, and manageable maintenance as data volumes grow. These characteristics directly affect the performance and scalability of AI-enabled database solutions.


Go to the DP-800 Exam Prep Hub main page

Implement vector search (DP-800 Exam Prep)

This post is a part of the DP-800: Developing AI-Enabled Database Solutions Exam Prep Hub.
This topic falls under these sections:
Implement AI capabilities in database solutions (25–30%)
   --> Design and implement intelligent search
      --> Implement vector search


Note that there are 10 practice questions (with answers) at the end of each section to help you solidify your knowledge of the material. Also, there are 4 practice tests with 30 questions each available from the hub's main page below the exam topics section.

Introduction

Implementing vector search is one of the foundational skills for building modern AI-enabled database applications. Vector search enables databases to retrieve information based on semantic meaning rather than exact keyword matches, making it essential for Retrieval-Augmented Generation (RAG), AI assistants, recommendation engines, semantic document search, knowledge management systems, and intelligent enterprise applications.


What Is Vector Search?

Traditional SQL queries search for exact values.

For example:

SELECT *
FROM Products
WHERE ProductName = 'Laptop';

or

WHERE Description LIKE '%wireless%'

These approaches rely on exact text matching.

However, AI applications often need to answer questions like:

“Find documents about reducing cloud costs.”

Relevant documents might contain:

  • Lower Azure spending
  • Optimize infrastructure expenses
  • Cloud cost optimization
  • Reduce operational costs

Although these documents contain different words, they share the same meaning.

Vector search enables databases to find these semantically related documents.


How Vector Search Works

Vector search consists of several stages.

User Query
Embedding Model
Query Vector
Vector Similarity Search
Nearest Neighbor Documents
(Optional)
Large Language Model (LLM)

Instead of comparing text directly, the database compares numeric vector representations generated by an embedding model.


What Is a Vector?

A vector is a high-dimensional numerical representation of data.

Example:

"Azure SQL Database"
[-0.134,
0.281,
0.998,
...
1536 dimensions]

Every document stored in the database has its own embedding vector.

When a user submits a query, the query is also converted into a vector.

The database then compares vectors mathematically to identify the most similar results.


Components of a Vector Search Solution

A complete vector search implementation includes several components.

1. Source Data

Examples include:

  • PDF files
  • Product catalogs
  • Emails
  • Knowledge articles
  • Web pages
  • Support tickets
  • SQL records

2. Embedding Model

The embedding model converts text into vectors.

Popular examples include:

  • Azure OpenAI Embeddings
  • OpenAI text embedding models
  • Sentence Transformers
  • Other compatible embedding models

The embedding model should remain consistent for both indexing and querying.


3. Vector Storage

Embeddings are stored inside the database.

Example table:

DocumentIDContentEmbedding
101Product Manual[1536 values]
102FAQ[1536 values]
103Warranty Guide[1536 values]

Modern SQL databases increasingly support dedicated vector data types.


4. Vector Index

Searching millions of vectors without an index would require comparing every vector.

Vector indexes organize embeddings for efficient similarity searches.

Common vector indexes include:

  • Flat (Exact Search)
  • HNSW
  • IVF
  • IVF + Product Quantization (PQ)

Approximate Nearest Neighbor (ANN) indexes are commonly used in production systems because they significantly reduce search latency while maintaining high recall.


5. Similarity Function

The database determines which vectors are closest.

Common similarity metrics include:

  • Cosine similarity
  • Euclidean distance
  • Dot product

Cosine similarity is the most common metric for semantic search.


Exact Search vs Approximate Search

Exact (Brute Force) Search

The database compares the query vector against every stored vector.

Advantages:

  • Perfect accuracy
  • Guaranteed nearest neighbors

Disadvantages:

  • Slow
  • Poor scalability

Best suited for:

  • Small datasets
  • Testing
  • Validation

Approximate Nearest Neighbor (ANN)

ANN indexes intelligently reduce the search space.

Advantages:

  • Extremely fast
  • Scales to millions or billions of vectors
  • Lower CPU utilization

Tradeoff:

Results are highly accurate but not mathematically perfect.

Most enterprise AI applications use ANN search.


Implementing Vector Search

A typical implementation follows these steps.

Step 1. Prepare Data

Collect the documents.

Examples:

  • Product manuals
  • Policies
  • Emails
  • Support articles

Clean the text by removing unnecessary formatting and duplicate content.


Step 2. Generate Embeddings

Use an embedding model to create vectors.

Example workflow:

Document
Embedding Model
1536-Dimensional Vector

Each document receives one or more embeddings.


Step 3. Store Embeddings

Store:

  • Original text
  • Metadata
  • Embedding vector

Example:

DocumentIDCategoryContentEmbedding
501HRVacation PolicyVector
502ITVPN SetupVector

Metadata enables additional filtering during searches.


Step 4. Create a Vector Index

The vector index accelerates similarity searches.

Without an index:

Query
Compare to every vector

With an ANN index:

Query
Index
Small candidate set
Best matches

Step 5. Convert User Query

The user’s search query is embedded using the same embedding model.

Example:

"How do I connect remotely?"
Embedding Model
Query Vector

Consistency is critical. Using a different embedding model for queries than for indexed documents can significantly reduce search quality.


Step 6. Perform Similarity Search

The database compares the query vector with stored vectors.

Example SQL pseudocode:

SELECT TOP 5
DocumentID,
SimilarityScore
FROM Documents
ORDER BY VECTOR_DISTANCE(Embedding, @QueryVector);

The exact syntax varies depending on the database platform and vector search implementation.


Step 7. Return Results

The application retrieves the closest documents.

Example:

RankDocument
1VPN Configuration Guide
2Remote Access FAQ
3Employee Network Policy

Vector Search Workflow

Documents
Generate Embeddings
Store Vectors
Create Vector Index
User Query
Generate Query Embedding
Similarity Search
Top Matching Documents

Filtering Vector Search Results

Many applications combine vector search with traditional SQL filtering.

Example:

Semantic Search
+
WHERE Department = 'Finance'
+
ORDER BY Similarity

This approach is often called hybrid filtering, allowing organizations to limit searches by structured metadata while still leveraging semantic similarity.

Examples of filters include:

  • Department
  • Date
  • Customer
  • Region
  • Security classification
  • Language

Hybrid Search

Hybrid search combines:

  • Keyword search
  • Full-text search
  • Vector search

Example:

Keyword Search
+
Vector Search
Combined Ranking
Final Results

Benefits include:

  • Higher relevance
  • Better handling of synonyms
  • Stronger ranking
  • Improved user satisfaction

Many enterprise AI search systems use hybrid search instead of vector search alone.


Using Vector Search in RAG

Retrieval-Augmented Generation relies heavily on vector search.

Workflow:

User Question
Embedding
Vector Search
Relevant Documents
LLM
Grounded Response

Instead of relying solely on the LLM’s training data, the model uses retrieved documents as grounding data.

Benefits:

  • More accurate responses
  • Reduced hallucinations
  • Access to current organizational knowledge

Common Vector Search Scenarios

Enterprise Knowledge Search

Users ask natural language questions.

Example:

“How do I reset my VPN password?”

The database retrieves the most semantically relevant documentation.


Customer Support

Support engineers search:

“Printer won’t connect.”

Relevant troubleshooting documents are retrieved even if they use different wording.


Product Recommendation

Customers searching for:

“Comfortable running shoes”

may receive products described as:

  • Lightweight trainers
  • Cushioned athletic footwear
  • Marathon shoes

Legal Document Search

Law firms search by legal concepts rather than exact wording.


Healthcare Knowledge Bases

Clinicians retrieve similar cases based on symptoms rather than identical terminology.


Performance Considerations

Database developers should evaluate:

Search Latency

Users expect responses within milliseconds.

ANN indexes dramatically reduce latency.


Recall

Recall measures how many of the true nearest neighbors are returned.

Higher recall generally improves RAG quality.


Index Size

Larger indexes often improve retrieval quality but require more memory.


Memory Consumption

HNSW indexes typically consume more RAM than compressed indexes.


Index Build Time

Large vector indexes may require significant time to build.

Plan for maintenance windows when rebuilding indexes.


Update Frequency

Applications with frequent inserts and deletes should use index types that efficiently support incremental updates.


Common Implementation Mistakes

Using Different Embedding Models

Documents embedded with one model should not be searched using vectors generated by a different model.


Using the Wrong Similarity Metric

Many embedding models assume cosine similarity.

Using Euclidean distance or dot product incorrectly may reduce search accuracy.


Not Creating a Vector Index

Searching without an index performs poorly on large datasets.


Ignoring Metadata

Metadata filtering significantly improves result quality.


Returning Too Many Documents

Retrieving excessive documents increases latency and may overwhelm downstream LLMs in RAG systems.


Best Practices

  • Use the same embedding model for indexing and querying.
  • Choose a similarity metric recommended for the embedding model.
  • Use ANN indexes for production environments.
  • Combine vector search with metadata filters when appropriate.
  • Consider hybrid search for the highest-quality results.
  • Benchmark recall, latency, and throughput using realistic workloads.
  • Monitor index growth and rebuild or optimize indexes when necessary.
  • Store both embeddings and the original source content.

DP-800 Exam Tips

Remember these key points for the exam:

  • Vector search retrieves data based on semantic similarity rather than exact text.
  • Embeddings are numerical representations generated by AI models.
  • The same embedding model should be used for both indexing and querying.
  • Vector indexes improve search performance by reducing the number of vector comparisons.
  • Approximate Nearest Neighbor (ANN) indexes provide fast searches with high recall.
  • Cosine similarity is the most commonly used metric for semantic search.
  • Hybrid search combines keyword search with vector search to improve relevance.
  • Vector search is a core component of Retrieval-Augmented Generation (RAG).

Practice Exam Questions

Question 1

A company is building a chatbot that answers employee questions using internal policy documents. The solution converts both documents and user queries into embeddings before searching for relevant information.

What is the primary purpose of generating embeddings?

A. To compress documents for storage

B. To represent text numerically so semantic similarity can be measured

C. To encrypt sensitive information

D. To improve SQL transaction performance

Answer: B

Explanation:
Embeddings convert text into high-dimensional numerical vectors that capture semantic meaning. These vectors enable similarity comparisons that go beyond exact keyword matching.


Question 2

A developer plans to implement vector search against a database containing 30 million document embeddings.

Which approach provides the best balance between scalability and query performance?

A. Sequentially compare every vector

B. Use a clustered index

C. Use an Approximate Nearest Neighbor (ANN) vector index

D. Create additional foreign keys

Answer: C

Explanation:
ANN indexes are specifically designed to support efficient vector similarity searches across very large datasets while maintaining high recall and low latency.


Question 3

A user searches for:

“Affordable cloud storage”

The returned documents discuss:

  • Cost-effective cloud backup
  • Low-cost online storage
  • Budget-friendly data storage

Why were these documents returned?

A. SQL wildcard matching

B. Lexical keyword matching

C. Primary key lookup

D. Semantic similarity using vector search

Answer: D

Explanation:
Vector search retrieves content based on semantic meaning rather than identical words, enabling related concepts and synonyms to be found.


Question 4

Which statement best describes hybrid search?

A. It combines vector search with keyword or full-text search.

B. It stores vectors in multiple databases.

C. It replaces embeddings with SQL indexes.

D. It searches only relational columns.

Answer: A

Explanation:
Hybrid search combines traditional lexical search with semantic vector search, often producing more relevant and comprehensive search results.


Question 5

Why should the same embedding model be used for both document indexing and query generation?

A. It reduces storage costs.

B. It eliminates the need for vector indexes.

C. It ensures vectors exist in the same semantic space for meaningful comparisons.

D. It automatically creates SQL indexes.

Answer: C

Explanation:
Embeddings generated by different models may occupy different vector spaces, making similarity calculations unreliable and reducing retrieval quality.


Question 6

What is the primary function of a vector index?

A. Encrypt embedding vectors

B. Reduce the number of vector comparisons during searches

C. Compress relational tables

D. Replace SQL indexes

Answer: B

Explanation:
Vector indexes organize embeddings so the search engine evaluates only the most promising candidates instead of comparing every stored vector.


Question 7

A Retrieval-Augmented Generation (RAG) application performs vector search before sending retrieved documents to a large language model.

Why is this retrieval step important?

A. It reduces SQL storage requirements.

B. It converts SQL tables into vectors.

C. It grounds the model with relevant information, improving response accuracy.

D. It eliminates the need for embeddings.

Answer: C

Explanation:
RAG retrieves relevant documents that provide context to the LLM, helping produce accurate, current, and evidence-based responses while reducing hallucinations.


Question 8

Which SQL capability is most commonly combined with vector search to narrow search results to specific business data?

A. Metadata filtering using WHERE clauses

B. ALTER TABLE statements

C. Transaction logging

D. Foreign key constraints

Answer: A

Explanation:
Combining vector search with structured SQL filters allows applications to restrict results by attributes such as department, region, or document type while maintaining semantic relevance.


Question 9

A developer performs vector similarity searches without creating a vector index.

What is the most likely consequence?

A. Embeddings become corrupted.

B. Query performance decreases significantly as the dataset grows.

C. SQL transactions stop working.

D. Documents cannot be embedded.

Answer: B

Explanation:
Without a vector index, the system typically performs an exhaustive comparison against every stored vector, resulting in much slower query performance on large datasets.


Question 10

Which statement best summarizes the role of vector search in AI-enabled database applications?

A. It replaces relational databases.

B. It removes the need for SQL queries.

C. It automatically generates embeddings.

D. It enables retrieval of information based on semantic meaning instead of exact text matching.

Answer: D

Explanation:
Vector search is designed to retrieve semantically similar information by comparing embedding vectors, making it a foundational capability for intelligent search, recommendation systems, and RAG-based applications.


Go to the DP-800 Exam Prep Hub main page

Implement hybrid search (DP-800 Exam Prep)

This post is a part of the DP-800: Developing AI-Enabled Database Solutions Exam Prep Hub.
This topic falls under these sections:
Implement AI capabilities in database solutions (25–30%)
   --> Design and implement intelligent search
      --> Implement hybrid search


Note that there are 10 practice questions (with answers) at the end of each section to help you solidify your knowledge of the material. Also, there are 4 practice tests with 30 questions each available from the hub's main page below the exam topics section.

Introduction

Hybrid search is a core capability for modern AI-enabled database solutions because it combines the strengths of traditional keyword search and vector (semantic) search. By leveraging both lexical and semantic matching techniques, hybrid search delivers more accurate, relevant, and context-aware search results than either approach alone. Hybrid search is widely used in Retrieval-Augmented Generation (RAG) applications, enterprise knowledge bases, AI assistants, recommendation systems, and intelligent search platforms.


What Is Hybrid Search?

Hybrid search combines multiple search techniques into a single query, typically including:

  • Keyword search
  • Full-text search
  • Vector (semantic) search

Instead of relying on only one search method, hybrid search retrieves candidates from multiple search engines and combines the results using a ranking algorithm.

For example, consider a user searching for:

“How do I reduce Azure storage costs?”

A keyword search might find documents containing the exact terms:

  • Azure
  • Storage
  • Costs

A vector search might retrieve documents discussing:

  • Lower cloud expenses
  • Optimize storage spending
  • Reduce infrastructure costs

Hybrid search combines both result sets and ranks the most relevant documents at the top.


Why Hybrid Search Is Important

Neither keyword search nor vector search is perfect by itself.

Keyword Search Strengths

Keyword search excels at finding:

  • Exact product names
  • Error codes
  • File names
  • Database object names
  • Technical terminology

Example:

SQL72014

A keyword search finds documents containing that exact error code.


Keyword Search Weaknesses

Keyword search struggles with:

  • Synonyms
  • Different wording
  • Natural language
  • Conceptual relationships

Example:

Search:

“Vacation policy”

Document:

“Paid time off guidelines”

Although both describe the same concept, keyword search may not find the document.


Vector Search Strengths

Vector search understands meaning.

Example:

Search:

“Improve application speed”

Documents discussing:

  • Performance optimization
  • Query tuning
  • Faster database execution

can all be returned because their embeddings are semantically similar.


Vector Search Weaknesses

Vector search may struggle with:

  • Product IDs
  • Version numbers
  • Error codes
  • Exact names
  • Highly specialized terminology

Example:

Searching for:

SQL71561

works better with keyword search.


Hybrid Search Combines Both Approaches

User Query
Keyword Search
+
Vector Search
Combined Results
Ranking
Top Results

This allows users to benefit from both lexical precision and semantic understanding.


How Hybrid Search Works

A hybrid search implementation generally follows these steps.

Step 1. User Submits a Query

Example:

“How do I configure Azure SQL backups?”


Step 2. Keyword Search Executes

The database searches for:

  • Azure
  • SQL
  • Backups
  • Configure

using:

  • Full-text indexes
  • SQL predicates
  • Traditional search indexes

Step 3. Vector Search Executes

The same query is converted into an embedding.

Query
Embedding Model
Vector

The vector is compared against stored document embeddings.


Step 4. Merge Results

Suppose keyword search returns:

DocumentScore
Backup Overview95
SQL Backup Guide90

Vector search returns:

DocumentScore
Disaster Recovery93
Data Protection88

The system merges these candidate sets.


Step 5. Rank Results

The ranking engine evaluates:

  • Keyword relevance
  • Semantic similarity
  • Metadata
  • Popularity
  • Freshness
  • Business rules

The highest-ranking documents are returned.


Components of a Hybrid Search Solution

Source Documents

Examples include:

  • PDFs
  • Product documentation
  • Knowledge articles
  • Support tickets
  • Policies
  • Emails
  • SQL records

Full-Text Index

Supports traditional keyword searching.

Optimized for:

  • Exact phrases
  • Words
  • Wildcards
  • Boolean searches

Embedding Model

Generates vector representations for documents and queries.

Examples:

  • Azure OpenAI Embeddings
  • OpenAI embedding models
  • Sentence Transformers

The same embedding model should be used during indexing and querying.


Vector Index

Stores embeddings for efficient semantic search.

Examples:

  • HNSW
  • IVF
  • Flat index
  • Product Quantization (PQ)

Ranking Engine

Combines multiple signals into a single relevance score.


Search Pipeline

User Query
Keyword Search
\
\
Ranking Engine
/
/
Vector Search
Combined Results

Both searches occur independently before the results are combined.


Ranking in Hybrid Search

Hybrid search is more than simply combining two result lists.

Each result receives a relevance score based on multiple factors.

Typical ranking signals include:

  • Keyword score
  • Vector similarity score
  • Document freshness
  • Popularity
  • User permissions
  • Metadata
  • Business importance

The ranking algorithm determines the final ordering.


Metadata Filtering

Hybrid search often includes structured SQL filters.

Example:

WHERE Department = 'Finance'

or

WHERE DocumentType = 'Policy'

The search becomes:

Keyword Search
+
Vector Search
+
Metadata Filters
Ranking

Filtering improves both relevance and performance.


Hybrid Search in RAG

Hybrid search is commonly used in Retrieval-Augmented Generation.

Workflow:

User Question
Hybrid Search
Relevant Documents
Large Language Model
Grounded Response

Benefits include:

  • Higher-quality context
  • Reduced hallucinations
  • More complete retrieval
  • Better factual accuracy

Example Scenario

Suppose an employee asks:

“How do I access my benefits after changing jobs?”

Keyword search retrieves:

  • Benefits
  • Jobs

Vector search retrieves:

  • Employee transition
  • HR onboarding
  • Employment status changes

Hybrid search combines both sets, increasing the likelihood of returning the most relevant documents.


Hybrid Search vs Keyword Search

FeatureKeyword SearchHybrid Search
Exact termsExcellentExcellent
SynonymsPoorExcellent
Natural languageLimitedExcellent
Error codesExcellentExcellent
Semantic understandingNoneExcellent
AI applicationsLimitedExcellent

Hybrid Search vs Vector Search

FeatureVector SearchHybrid Search
Semantic understandingExcellentExcellent
Exact identifiersModerateExcellent
Error codesModerateExcellent
Product namesModerateExcellent
Natural languageExcellentExcellent
Overall relevanceHighVery High

Benefits of Hybrid Search

Better Relevance

Combines multiple search signals.


Handles Synonyms

Users don’t need exact wording.


Supports Technical Queries

Keyword search finds:

  • Error codes
  • File names
  • Product names

Supports Natural Language

Vector search understands concepts.


Improved User Satisfaction

Users receive better search results.


Better RAG Responses

The LLM receives more relevant context.


Challenges

Increased Complexity

Two search systems must be maintained.


Higher Resource Usage

Both keyword and vector searches execute.


Ranking Tuning

Determining the correct weighting between keyword and semantic scores may require experimentation.


Embedding Maintenance

Embeddings should be regenerated when source content changes significantly or when migrating to a new embedding model.


Common Hybrid Search Scenarios

Enterprise Knowledge Bases

Employees search documentation using natural language.


Customer Support

Support agents retrieve troubleshooting articles using both error codes and descriptive questions.


Product Catalogs

Customers search using product names, descriptions, or intent.


Healthcare

Clinicians search using symptoms while also matching standardized medical terminology.


Legal Research

Lawyers search using statutes, case numbers, and legal concepts.


Financial Services

Analysts search reports using account identifiers and descriptive business questions.


Best Practices

  • Combine full-text and vector search for production AI applications.
  • Use the same embedding model during indexing and querying.
  • Create appropriate full-text and vector indexes.
  • Apply metadata filters whenever possible.
  • Tune ranking weights using representative user queries.
  • Evaluate both precision and recall during testing.
  • Continuously monitor search quality and user feedback.
  • Refresh embeddings when source documents change significantly.
  • Secure search results using role-based access controls and document permissions.

DP-800 Exam Tips

Remember these key points for the exam:

  • Hybrid search combines traditional keyword search with vector search.
  • Keyword search excels at exact terms, identifiers, and technical strings.
  • Vector search excels at semantic meaning and natural language.
  • Hybrid search generally provides better relevance than either approach alone.
  • Ranking combines multiple signals, including lexical relevance, semantic similarity, and metadata.
  • Metadata filtering improves both performance and result quality.
  • Hybrid search is commonly used in Retrieval-Augmented Generation (RAG) systems.
  • The same embedding model should be used for both indexing and querying to ensure meaningful vector comparisons.

Practice Exam Questions

Question 1

A company is building an AI-powered knowledge base that must support searches for both exact error codes and natural language questions.

Which search approach is most appropriate?

A. Hybrid search

B. Keyword search only

C. Vector search only

D. Relational indexing only

Answer: A

Explanation:
Hybrid search combines keyword and vector search, enabling both exact matching for error codes and semantic matching for natural language queries.


Question 2

A user searches for:

“Improve database response time”

The system returns documents discussing query tuning, indexing strategies, and SQL optimization, even though those exact words were not used.

Which component enabled this behavior?

A. Full-text search

B. Vector search

C. Clustered indexes

D. Foreign key constraints

Answer: B

Explanation:
Vector search compares embeddings that capture semantic meaning, allowing conceptually related documents to be retrieved even when different wording is used.


Question 3

What is the primary purpose of the ranking engine in a hybrid search solution?

A. Generate document embeddings

B. Create vector indexes

C. Combine and order results from multiple search methods

D. Encrypt search results

Answer: C

Explanation:
The ranking engine merges results from keyword and vector searches and orders them using relevance signals such as lexical score, semantic similarity, freshness, and metadata.


Question 4

Which type of query is generally handled most effectively by keyword search?

A. “How can I reduce cloud expenses?”

B. “Best practices for disaster recovery”

C. “Ways to improve SQL performance”

D. “SQL71561”

Answer: D

Explanation:
Exact identifiers such as error codes, product names, and version numbers are best handled using keyword or full-text search.


Question 5

Why is hybrid search commonly used in Retrieval-Augmented Generation (RAG) applications?

A. It eliminates the need for embeddings.

B. It improves retrieval quality by combining lexical and semantic matching.

C. It replaces large language models.

D. It removes the need for vector indexes.

Answer: B

Explanation:
Hybrid search retrieves more comprehensive and relevant information than either keyword or vector search alone, providing higher-quality context to the LLM.


Question 6

A search solution first performs keyword search, then vector similarity search, and finally combines both result sets.

Which step typically follows next?

A. Delete duplicate documents from the database.

B. Recreate all vector indexes.

C. Rank the combined results using relevance signals.

D. Generate new embeddings for every document.

Answer: C

Explanation:
After gathering candidate documents, the ranking engine evaluates multiple relevance signals to determine the final ordering presented to the user.


Question 7

Which statement best describes metadata filtering in hybrid search?

A. It replaces vector search.

B. It restricts search results using structured attributes such as department or document type.

C. It converts SQL tables into embeddings.

D. It automatically updates document embeddings.

Answer: B

Explanation:
Metadata filters narrow the search scope using structured data while still allowing semantic and keyword search within the filtered dataset.


Question 8

A developer configures hybrid search using one embedding model for indexing documents and a different embedding model for processing user queries.

What is the most likely result?

A. Improved semantic accuracy.

B. Reduced index size.

C. Faster query execution.

D. Lower-quality semantic matches because vectors occupy different embedding spaces.

Answer: D

Explanation:
Embeddings produced by different models are generally not directly comparable, leading to poorer semantic similarity calculations and less relevant search results.


Question 9

Which advantage does hybrid search have over vector search alone?

A. It supports exact matching for identifiers while preserving semantic search capabilities.

B. It eliminates the need for full-text indexes.

C. It guarantees mathematically perfect search results.

D. It removes the need for metadata.

Answer: A

Explanation:
Hybrid search enhances vector search by adding lexical matching, making it more effective for exact terms such as product names, file names, and error codes.


Question 10

Which best practice should a database developer follow when implementing hybrid search?

A. Use different embedding models for documents and queries.

B. Disable metadata filtering to improve semantic search.

C. Combine full-text search, vector search, and structured filtering to improve relevance.

D. Use exhaustive vector search for every production workload regardless of size.

Answer: C

Explanation:
A well-designed hybrid search solution combines lexical search, semantic search, and structured metadata filtering to maximize relevance, scalability, and user satisfaction in AI-enabled database applications.


Go to the DP-800 Exam Prep Hub main page

Implement reciprocal rank fusion (RRF) (DP-800 Exam Prep)

This post is a part of the DP-800: Developing AI-Enabled Database Solutions Exam Prep Hub.
This topic falls under these sections:
Implement AI capabilities in database solutions (25–30%)
   --> Design and implement intelligent search
      --> Implement reciprocal rank fusion (RRF)


Note that there are 10 practice questions (with answers) at the end of each section to help you solidify your knowledge of the material. Also, there are 4 practice tests with 30 questions each available from the hub's main page below the exam topics section.

Introduction

Reciprocal Rank Fusion (RRF) is an important ranking technique used in modern hybrid search systems. It enables AI-enabled database solutions to combine results from multiple search algorithms—such as full-text search and vector search—into a single ranked result set. RRF is widely used in Retrieval-Augmented Generation (RAG), enterprise search, Azure AI Search, recommendation systems, and intelligent database applications because it consistently produces high-quality search results without requiring complex score normalization.


What Is Reciprocal Rank Fusion (RRF)?

Reciprocal Rank Fusion (RRF) is a rank aggregation algorithm that combines multiple independently ranked result lists into one unified ranking.

Instead of comparing the actual relevance scores produced by different search algorithms, RRF considers only the position (rank) of each document within each result list.

This makes RRF particularly effective when combining search methods that produce different types of scores.

For example:

  • Full-text search may produce BM25 relevance scores.
  • Vector search may produce cosine similarity scores.
  • Semantic rerankers may produce AI-generated relevance scores.

Because these scoring systems are different and often not directly comparable, RRF combines rankings instead of raw scores.


Why Is RRF Needed?

Modern AI search systems often execute multiple searches simultaneously.

Example:

User query:

“How do I secure Azure SQL backups?”

The search system performs:

  • Full-text search
  • Vector search
  • Metadata filtering
  • Optional semantic reranking

Each search returns different documents with different scoring methods.

Without RRF, combining these results would be difficult because:

  • BM25 scores are not directly comparable to cosine similarity scores.
  • Different algorithms have different score ranges.
  • Some algorithms produce probabilities.
  • Others produce similarity values.

RRF eliminates this problem by using document rankings instead of score values.


Traditional Score Combination Problems

Suppose two searches return:

Keyword Search

RankDocumentBM25 Score
1Doc A98
2Doc B91
3Doc C88

Vector Search

RankDocumentCosine Similarity
1Doc C0.95
2Doc D0.94
3Doc A0.92

Notice:

  • BM25 scores range around 90–100.
  • Cosine similarity ranges between approximately -1 and 1 (typically 0–1 for normalized embeddings).

Adding these scores directly would not produce meaningful results.


How RRF Works

RRF ignores the raw scores.

Instead, it assigns each document a score based on its ranking position.

Conceptually:

RRF Score = Σ 1 / (k + rank)

Where:

  • rank = the document’s position in each result list.
  • k = a constant (commonly 60) that reduces the impact of very high rankings and smooths the score distribution.

The exact value of k is implementation-specific, but many search platforms—including Azure AI Search—use a default value of 60.

The important DP-800 exam concept is that RRF combines rankings rather than raw relevance scores.


Example of RRF

Suppose two searches return:

Keyword Search

RankDocument
1A
2B
3C

Vector Search

RankDocument
1C
2A
3D

RRF rewards documents appearing in both lists.

Document A:

  • Rank 1 in keyword search
  • Rank 2 in vector search

Document C:

  • Rank 3 in keyword search
  • Rank 1 in vector search

Both receive relatively high RRF scores because they rank well in multiple searches.

Documents appearing in only one list receive lower combined scores.


RRF Search Pipeline

User Query
Keyword Search
\
\
\
RRF
/
/
Vector Search
Combined Ranked Results

Each search executes independently.

RRF merges the rankings.


Why Ranking Is Better Than Combining Scores

Consider two scoring systems.

Keyword search:

95
82
79

Vector search:

0.97
0.94
0.92

These values represent different measurements.

Instead of trying to normalize them, RRF simply uses:

Rank 1
Rank 2
Rank 3

This approach is:

  • Simpler
  • More stable
  • More reliable
  • Independent of score scales

RRF in Hybrid Search

Hybrid search commonly executes:

  • Keyword search
  • Full-text search
  • Vector search

Each produces candidate documents.

RRF combines them into one ranked list.

Example:

Keyword Results
RRF
Vector Results
Final Results

This is one of the most common implementations in enterprise AI search systems.


RRF in Retrieval-Augmented Generation (RAG)

RAG applications depend on retrieving the most relevant documents.

Workflow:

User Question
Hybrid Search
RRF Ranking
Top Documents
Large Language Model
Grounded Response

Benefits include:

  • Better retrieval quality
  • Better grounding
  • More complete context
  • Reduced hallucinations

Advantages of RRF

Simple

No complex score normalization is required.


Algorithm Independent

Works with:

  • BM25
  • Vector similarity
  • AI ranking
  • Other retrieval algorithms

Better Retrieval Quality

Documents consistently ranked highly across multiple search methods naturally rise to the top.


Robust

Minor score differences between search algorithms do not significantly affect results.


Easy to Scale

Additional search algorithms can be incorporated into the fusion process without redesigning the ranking approach.


Example Enterprise Scenario

Suppose an employee searches:

“Configure disaster recovery”

Keyword search returns:

  • Disaster Recovery Guide
  • Backup Documentation

Vector search returns:

  • Business Continuity Planning
  • Disaster Recovery Guide
  • Failover Procedures

RRF recognizes that Disaster Recovery Guide appears near the top of both lists and promotes it in the final ranking.


RRF Compared to Score Averaging

Score Averaging

Requires:

  • Score normalization
  • Matching score scales
  • Additional tuning

Problems:

  • Different algorithms use different scoring methods.
  • Difficult to compare heterogeneous scores.

Reciprocal Rank Fusion

Uses:

  • Ranking positions only

Benefits:

  • Simpler
  • More reliable
  • Independent of scoring scales
  • Common in production AI search systems

RRF Compared to Semantic Reranking

These concepts are related but different.

Reciprocal Rank FusionSemantic Reranking
Combines multiple ranked listsReorders documents using an AI model
Uses document positionsUses semantic understanding
Doesn’t read document contentEvaluates document meaning
Runs before semantic reranking in many architecturesOften runs after candidate retrieval

Many enterprise AI search solutions use both techniques:

  1. Keyword search
  2. Vector search
  3. RRF
  4. Semantic reranking
  5. Return results

RRF in AI-Enabled Database Solutions

Modern AI-enabled SQL solutions increasingly combine:

  • SQL filtering
  • Full-text search
  • Vector search
  • Hybrid search
  • RRF
  • Retrieval-Augmented Generation

These capabilities enable intelligent applications to retrieve highly relevant information while leveraging existing relational database technologies.


Performance Considerations

Multiple Searches

Hybrid search requires multiple searches to execute.

This increases computational work compared to using only one search method.


Improved Relevance

The additional processing typically results in significantly better retrieval quality.


Candidate List Size

Most systems apply RRF to the top-ranked candidates from each search rather than the entire dataset.


Low Computational Overhead

RRF calculations are lightweight because they operate on rankings instead of comparing vector values or processing document contents.


Best Practices

  • Use RRF when combining keyword and vector search results.
  • Avoid directly comparing raw scores from different retrieval algorithms.
  • Retrieve an appropriate number of candidate documents from each search before applying RRF.
  • Combine RRF with metadata filtering when appropriate.
  • Use semantic reranking after RRF if supported by the platform.
  • Evaluate retrieval quality using representative business queries.
  • Monitor precision and recall when tuning hybrid search solutions.

DP-800 Exam Tips

Remember these key points for the exam:

  • Reciprocal Rank Fusion (RRF) combines ranked search results, not raw relevance scores.
  • RRF is commonly used in hybrid search systems.
  • RRF works well because keyword search scores and vector similarity scores are not directly comparable.
  • Documents ranked highly by multiple search algorithms receive higher final rankings.
  • RRF is lightweight, scalable, and independent of the underlying retrieval algorithms.
  • RRF is frequently used in Retrieval-Augmented Generation (RAG) to improve document retrieval before passing context to an LLM.
  • Semantic reranking and RRF are complementary techniques; RRF typically merges candidate lists before optional semantic reranking.

Practice Exam Questions

Question 1

A developer is combining results from a keyword search and a vector similarity search. The two searches produce different scoring scales.

Which ranking technique is specifically designed to combine these results without comparing the raw scores?

A. Reciprocal Rank Fusion (RRF)

B. Euclidean Distance

C. Product Quantization

D. HNSW

Answer: A

Explanation:
RRF combines ranked result lists instead of raw relevance scores, making it ideal for merging results from search algorithms that use different scoring methods.


Question 2

What information does Reciprocal Rank Fusion primarily use when calculating a document’s combined relevance?

A. The document’s embedding values

B. The raw BM25 score

C. The document’s position (rank) in each result list

D. The number of words in the document

Answer: C

Explanation:
RRF uses the ranking position of documents in each search result list rather than their raw scores, allowing it to combine heterogeneous search results effectively.


Question 3

Why is RRF commonly used in hybrid search?

A. It generates embeddings automatically.

B. It combines keyword and vector search results using document rankings.

C. It replaces vector indexes.

D. It eliminates full-text search.

Answer: B

Explanation:
Hybrid search often combines keyword and vector searches. RRF merges the ranked results without requiring score normalization.


Question 4

A document appears near the top of both keyword search and vector search results.

How will RRF typically treat this document?

A. It will remove it as a duplicate.

B. It will assign it a lower ranking because it appears twice.

C. It will ignore the vector search ranking.

D. It will rank the document higher in the final results.

Answer: D

Explanation:
Documents that consistently rank highly across multiple search methods receive higher combined RRF scores and are promoted in the final ranking.


Question 5

Which challenge does RRF help solve?

A. Encrypting document embeddings

B. Creating vector indexes

C. Combining search algorithms that produce different relevance score scales

D. Compressing embedding vectors

Answer: C

Explanation:
Because keyword search, vector search, and semantic search often use different scoring systems, RRF combines rankings instead of attempting to compare incompatible scores.


Question 6

Which statement best describes Reciprocal Rank Fusion?

A. It performs semantic reranking by analyzing document content.

B. It combines ranked search results from multiple retrieval methods.

C. It generates vector embeddings.

D. It creates Approximate Nearest Neighbor indexes.

Answer: B

Explanation:
RRF is a rank aggregation algorithm that merges multiple ranked lists into a single ordered result set.


Question 7

In a Retrieval-Augmented Generation (RAG) solution, where is RRF typically applied?

A. After the large language model generates its response

B. Before document retrieval begins

C. During the combination of candidate search results before providing context to the LLM

D. During embedding generation

Answer: C

Explanation:
RRF is used after multiple retrieval methods return candidate documents and before the final context is passed to the LLM.


Question 8

Which statement accurately compares RRF and semantic reranking?

A. They perform the same function.

B. RRF replaces semantic reranking.

C. Semantic reranking combines ranked lists using reciprocal values.

D. RRF merges ranked results, while semantic reranking uses AI to evaluate document meaning.

Answer: D

Explanation:
RRF aggregates ranked lists from multiple search methods, whereas semantic reranking analyzes document content and query meaning to reorder results.


Question 9

What is a key advantage of using RRF instead of averaging raw search scores?

A. It requires complex score normalization.

B. It is independent of the underlying scoring scales used by different search algorithms.

C. It eliminates the need for vector search.

D. It always returns mathematically exact nearest neighbors.

Answer: B

Explanation:
RRF avoids the complexities of comparing different scoring systems by relying solely on ranking positions.


Question 10

A database developer is implementing hybrid search in an AI-enabled SQL solution.

Which sequence best reflects a common enterprise retrieval pipeline?

A. Generate embeddings → LLM → Vector search → Keyword search

B. Semantic reranking → Embedding generation → Keyword search

C. Keyword search → Vector search → Reciprocal Rank Fusion → Optional semantic reranking → Return results

D. Product Quantization → SQL backup → Semantic reranking

Answer: C

Explanation:
A common enterprise hybrid search workflow retrieves candidate documents using keyword and vector search, combines them using RRF, optionally applies semantic reranking, and then returns the highest-quality results for use in applications such as RAG.


Go to the DP-800 Exam Prep Hub main page

Evaluate performance of vector and hybrid search (DP-800 Exam Prep)

This post is a part of the DP-800: Developing AI-Enabled Database Solutions Exam Prep Hub.
This topic falls under these sections:
Implement AI capabilities in database solutions (25–30%)
   --> Design and implement intelligent search
      --> Evaluate performance of vector and hybrid search


Note that there are 10 practice questions (with answers) at the end of each section to help you solidify your knowledge of the material. Also, there are 4 practice tests with 30 questions each available from the hub's main page below the exam topics section.

Introduction

Evaluating the performance of vector and hybrid search solutions is a critical responsibility when developing AI-enabled database applications. While implementing vector search is important, ensuring that the search solution consistently returns accurate, relevant, fast, and scalable results is equally essential. Database developers must understand how to measure search quality, optimize retrieval performance, balance latency with accuracy, and monitor search systems over time.

This knowledge is especially important for applications such as:

  • Retrieval-Augmented Generation (RAG)
  • Enterprise knowledge search
  • AI-powered chatbots
  • Document retrieval
  • Recommendation systems
  • Intelligent search applications

Why Performance Evaluation Matters

Unlike traditional SQL queries that typically return deterministic results, vector and hybrid search systems retrieve documents based on statistical similarity.

This means there is always a balance between:

  • Search speed
  • Search accuracy
  • Resource consumption
  • Scalability

A search system that responds instantly but returns irrelevant documents is not useful.

Likewise, a system that returns perfect results but requires several seconds per query may not satisfy user expectations.

The goal is to optimize the entire search experience.


Key Performance Metrics

Several metrics are commonly used to evaluate vector and hybrid search.

Query Latency

Latency measures how long a search takes to return results.

Example:

User Query
120 ms
Results Returned

Lower latency improves user experience.

Typical enterprise AI search systems aim for response times measured in milliseconds.

Factors affecting latency include:

  • Index type
  • Dataset size
  • Hardware resources
  • Number of search algorithms executed
  • Network latency
  • Number of retrieved documents

Throughput

Throughput measures the number of search requests a system can process within a given time.

Examples:

  • Searches per second
  • Queries per minute

Higher throughput enables more concurrent users.

Throughput depends on:

  • CPU
  • Memory
  • Index efficiency
  • Parallel processing
  • Database architecture

Recall

Recall measures how many relevant documents are successfully retrieved.

Example:

Relevant documents:

A
B
C
D
E

Returned documents:

A
B
C
X
Y

Recall:

3 / 5 = 60%

Higher recall generally improves RAG quality because more relevant information is available to the large language model.


Precision

Precision measures how many returned documents are actually relevant.

Example:

Returned:

A
B
C
X
Y

Relevant:

A
B
C

Precision:

3 / 5 = 60%

High precision reduces irrelevant search results.


F1 Score

The F1 Score combines precision and recall into a single metric.

It is especially useful when both false positives and false negatives matter.

Higher F1 scores indicate a better overall balance between retrieving relevant documents and avoiding irrelevant ones.


Mean Reciprocal Rank (MRR)

MRR measures how highly the first relevant result appears in the ranked list.

Example:

Relevant document positions:

QueryFirst Relevant Result
Query 1Rank 1
Query 2Rank 2
Query 3Rank 4

Higher MRR indicates users find relevant information more quickly.

MRR is commonly used when evaluating question-answering systems and RAG applications.


Normalized Discounted Cumulative Gain (NDCG)

NDCG measures:

  • Ranking quality
  • Position of relevant documents
  • Graded relevance

Unlike recall, NDCG rewards placing the most relevant documents near the top.

This is especially important because users rarely read beyond the first few search results.


Evaluating Vector Search

When evaluating vector search, developers typically measure:

  • Recall
  • Precision
  • Latency
  • Index build time
  • Memory usage
  • Storage requirements

Index Performance

Questions include:

  • How quickly are searches completed?
  • How much memory does the index require?
  • How long does index creation take?
  • How efficiently are inserts handled?

Search Quality

Evaluate:

  • Are similar documents retrieved?
  • Are unrelated documents excluded?
  • Are synonyms recognized?
  • Does semantic similarity match user expectations?

Evaluating Hybrid Search

Hybrid search combines:

  • Full-text search
  • Vector search
  • Metadata filtering
  • Ranking algorithms such as Reciprocal Rank Fusion (RRF)
  • Optional semantic reranking

Because more components participate, additional evaluation is necessary.


Ranking Quality

Developers evaluate whether:

  • Exact matches appear near the top.
  • Semantically relevant documents are included.
  • Duplicate results are minimized.
  • Ranking is consistent.

Hybrid Relevance

Example query:

“Reduce Azure costs”

Good hybrid results may include:

  • Azure cost optimization
  • Cloud spending reduction
  • Budget management
  • Reserved capacity guidance

Poor hybrid results may include unrelated Azure topics.


Measuring Retrieval Quality

Many organizations create benchmark datasets.

Example:

Question:

“How do I configure VPN access?”

Expected documents:

  • VPN Setup Guide
  • Remote Access Policy
  • Authentication Configuration

The search system is evaluated based on whether these expected documents appear in the returned results.


Human Evaluation

Automated metrics cannot evaluate every aspect of search quality.

Organizations often perform manual reviews.

Experts examine:

  • Relevance
  • Completeness
  • Ranking quality
  • Consistency

Human evaluation is particularly valuable for RAG applications.


Offline Evaluation

Offline testing uses historical datasets.

Advantages:

  • Repeatable
  • Safe
  • Fast
  • No production impact

Developers compare:

  • Multiple embedding models
  • Index types
  • Similarity metrics
  • Ranking algorithms

Online Evaluation

Online evaluation uses live users.

Common techniques include:

A/B Testing

Group A:

Current search system

Group B:

New search implementation

Metrics compared include:

  • Click-through rate
  • User satisfaction
  • Search success
  • Session completion

User Feedback

Collect feedback such as:

  • Helpful
  • Not Helpful

User feedback helps improve future search tuning.


Factors Affecting Vector Search Performance

Embedding Quality

Poor embeddings reduce retrieval quality regardless of index performance.

Always choose embedding models appropriate for the domain.


Similarity Metric

Common choices:

  • Cosine similarity
  • Dot product
  • Euclidean distance

Using the wrong metric can reduce search accuracy.


Vector Index Type

Different index types provide different tradeoffs.

IndexSpeedRecallMemory
FlatSlowHighestModerate
HNSWVery FastVery HighHigh
IVFFastHighModerate
IVF + PQVery FastModerate-HighLow

Candidate Set Size

Returning more candidate documents often increases recall.

However:

  • Latency increases.
  • More data must be reranked.
  • LLM token usage increases in RAG.

Balance is important.


Metadata Filtering

Filtering improves:

  • Precision
  • Latency

Example:

WHERE Department = 'Finance'

Searching fewer documents reduces processing time while improving relevance.


Evaluating Hybrid Search Components

Keyword Search

Evaluate:

  • Exact matches
  • Phrase matching
  • Synonym handling
  • Technical terminology

Vector Search

Evaluate:

  • Semantic understanding
  • Related concepts
  • Context awareness

Reciprocal Rank Fusion (RRF)

Evaluate:

  • Ranking consistency
  • Combined relevance
  • Candidate diversity

Semantic Reranking

Evaluate:

  • Final ranking quality
  • User satisfaction
  • Response accuracy

Common Performance Bottlenecks

Missing Vector Index

Searching every embedding significantly increases latency.


Poor Embeddings

Weak embeddings reduce semantic quality.


Excessive Candidate Retrieval

Retrieving hundreds of documents unnecessarily increases reranking and LLM processing time.


Large Embedding Dimensions

Higher-dimensional embeddings require:

  • More storage
  • More memory
  • More computation

Frequent Index Rebuilds

Rebuilding indexes too frequently can consume unnecessary resources.

Use incremental updates where supported.


Optimization Techniques

Choose the Correct Index

Examples:

  • Small datasets → Flat
  • Medium datasets → HNSW
  • Very large datasets → IVF or IVF + PQ

Tune Candidate Count

Retrieve only the number of documents needed.


Use Metadata Filters

Reduce unnecessary searches.


Optimize Embeddings

Select high-quality embedding models.


Use Hybrid Search

Combining lexical and semantic search generally improves relevance.


Apply Semantic Reranking

Use reranking on a limited candidate set to improve final result quality.


Performance Monitoring

Production systems should monitor:

  • Average latency
  • Peak latency
  • Recall
  • Precision
  • Throughput
  • Memory usage
  • Index size
  • Search failures
  • User satisfaction
  • Search abandonment rate

Monitoring enables proactive tuning as data volumes and usage patterns evolve.


Best Practices

  • Benchmark search quality before deployment.
  • Measure both latency and retrieval quality.
  • Use benchmark datasets with known expected results.
  • Combine automated metrics with human evaluation.
  • Tune candidate retrieval size based on workload.
  • Select the appropriate vector index for dataset size.
  • Monitor production search metrics continuously.
  • Refresh embeddings when source data changes significantly.
  • Evaluate hybrid search using realistic business queries.
  • Test changes in a staging environment before production deployment.

DP-800 Exam Tips

Remember these key points for the exam:

  • Vector search performance should be evaluated using both speed and retrieval quality metrics.
  • Recall measures how many relevant documents are retrieved.
  • Precision measures how many returned documents are relevant.
  • MRR evaluates how quickly users encounter the first relevant result.
  • NDCG evaluates the quality of document ranking.
  • Hybrid search should be evaluated as a complete pipeline, including keyword search, vector search, RRF, and optional semantic reranking.
  • Metadata filtering improves both precision and performance.
  • Human evaluation remains important because automated metrics cannot fully measure search usefulness.
  • Production systems should continuously monitor latency, recall, throughput, and user satisfaction.

Practice Exam Questions

Question 1

A database developer is evaluating a vector search solution. Which metric measures the percentage of retrieved documents that are actually relevant?

A. Recall

B. Latency

C. Precision

D. Throughput

Answer: C

Explanation:
Precision measures the proportion of retrieved documents that are relevant. High precision indicates that the search results contain few irrelevant documents.


Question 2

A Retrieval-Augmented Generation (RAG) application consistently retrieves only three of the five relevant documents for most user queries.

Which performance metric is primarily affected?

A. Recall

B. Mean Reciprocal Rank (MRR)

C. Throughput

D. Query latency

Answer: A

Explanation:
Recall measures how many relevant documents are successfully retrieved. Missing relevant documents lowers the recall score.


Question 3

Which metric evaluates how quickly users encounter the first relevant search result?

A. F1 Score

B. Mean Reciprocal Rank (MRR)

C. Precision

D. Throughput

Answer: B

Explanation:
MRR evaluates the ranking position of the first relevant result, rewarding systems that place useful documents near the top of the results list.


Question 4

A search solution returns highly relevant documents, but users complain that responses take several seconds.

Which performance metric should the development team investigate first?

A. Index build time

B. Storage utilization

C. Embedding dimension

D. Query latency

Answer: D

Explanation:
Query latency measures the time required to return search results. High latency negatively impacts the user experience, even when retrieval quality is good.


Question 5

Which statement best describes hybrid search performance evaluation?

A. Only vector search accuracy needs to be measured.

B. Only keyword search latency matters.

C. Evaluation should include keyword search, vector search, ranking quality, and overall retrieval performance.

D. Performance is determined solely by embedding size.

Answer: C

Explanation:
Hybrid search combines multiple retrieval methods, so developers should evaluate the complete search pipeline rather than a single component.


Question 6

A developer increases the number of candidate documents retrieved before semantic reranking.

What is the most likely tradeoff?

A. Lower latency and reduced memory usage

B. Higher recall but increased latency and reranking costs

C. Reduced recall with faster indexing

D. Elimination of vector indexing requirements

Answer: B

Explanation:
Retrieving more candidate documents increases the likelihood of finding relevant information but also increases processing time, reranking effort, and LLM token usage.


Question 7

Why is human evaluation still valuable when assessing AI-powered search systems?

A. Automated metrics cannot fully measure user relevance and usefulness.

B. Human evaluation eliminates the need for benchmark datasets.

C. Human reviewers create vector indexes.

D. Human evaluation replaces latency testing.

Answer: A

Explanation:
While automated metrics quantify retrieval quality, human reviewers can assess contextual relevance, completeness, and overall usefulness from a user perspective.


Question 8

Which optimization technique can improve both search precision and query performance?

A. Increasing embedding dimensions indefinitely

B. Removing vector indexes

C. Using metadata filtering to narrow the search scope

D. Returning every matching document

Answer: C

Explanation:
Metadata filters reduce the number of candidate documents that must be searched, improving both relevance and performance.


Question 9

Which performance metric evaluates the overall quality of document ranking by giving more credit when highly relevant documents appear near the top of the results?

A. Recall

B. Precision

C. Throughput

D. Normalized Discounted Cumulative Gain (NDCG)

Answer: D

Explanation:
NDCG measures ranking quality by considering both document relevance and the position of documents in the ranked results, rewarding systems that place the most relevant items first.


Question 10

A development team wants to compare two different embedding models before deploying a new search solution.

Which evaluation approach is most appropriate?

A. Online A/B testing only

B. Disable benchmarking and rely on production feedback

C. Conduct repeatable offline testing using benchmark datasets with expected search results

D. Measure only CPU utilization

Answer: C

Explanation:
Offline benchmarking with known datasets enables developers to compare embedding models, similarity metrics, and indexing strategies safely and consistently before deploying changes to production.


Go to the DP-800 Exam Prep Hub main page

Identify use cases for RAG (DP-800 Exam Prep)

This post is a part of the DP-800: Developing AI-Enabled Database Solutions Exam Prep Hub.
This topic falls under these sections:
Implement AI capabilities in database solutions (25–30%)
   --> Design and implement retrieval-augmented generation (RAG)
      --> Identify use cases for RAG


Note that there are 10 practice questions (with answers) at the end of each section to help you solidify your knowledge of the material. Also, there are 4 practice tests with 30 questions each available from the hub's main page below the exam topics section.

Introduction

Retrieval-Augmented Generation (RAG) is one of the most important architectural patterns in modern AI-enabled database applications. Rather than relying solely on the knowledge contained within a Large Language Model (LLM), RAG retrieves relevant information from trusted data sources at query time and supplies that information to the model before it generates a response.

For the DP-800 exam, you should understand when RAG is appropriate, which business problems it solves, its advantages and limitations, and the types of applications that benefit most from its use.


What Is Retrieval-Augmented Generation (RAG)?

Retrieval-Augmented Generation (RAG) is an AI architecture that combines:

  • Information retrieval
  • Vector search
  • Large Language Models (LLMs)

Instead of asking an LLM to answer a question solely from its training data, a RAG system first retrieves relevant information from a database, document repository, or knowledge base.

The retrieved information is then included in the prompt sent to the LLM.

The workflow looks like this:

User Question
Generate Query Embedding
Vector or Hybrid Search
Retrieve Relevant Documents
Build Prompt with Retrieved Context
Large Language Model
Grounded Response

This process enables the model to answer using current, organization-specific, and trusted information.


Why RAG Is Needed

LLMs have several limitations when used independently.

These include:

  • Knowledge is limited to training data.
  • Information may become outdated.
  • Models cannot automatically access private organizational data.
  • Responses may contain hallucinations (confident but incorrect information).

RAG addresses these limitations by retrieving external information before response generation.

For example:

Without RAG:

“What is our company’s parental leave policy?”

The LLM has no knowledge of an organization’s private HR documents.

With RAG:

The system retrieves the latest HR policy document and provides it to the LLM, enabling it to generate an accurate, grounded response.


When Should You Use RAG?

RAG is most valuable when answers depend on information that is:

  • Frequently updated
  • Organization-specific
  • Too large to include in prompts directly
  • Stored in databases or documents
  • Required to be accurate and traceable

Typical sources include:

  • SQL databases
  • Knowledge bases
  • PDFs
  • SharePoint libraries
  • Wikis
  • Product documentation
  • Policies
  • Support articles
  • Contracts
  • Technical manuals

Common Business Use Cases

1. Enterprise Knowledge Management

One of the most common RAG implementations is an internal knowledge assistant.

Employees can ask questions such as:

“How do I request family medical leave?”

The system retrieves HR documentation and generates a conversational answer.

Benefits include:

  • Faster information access
  • Reduced HR workload
  • Consistent answers
  • Always uses the latest documents

2. Customer Support

Support organizations often maintain thousands of troubleshooting articles.

Example question:

“Why won’t my VPN connect?”

Instead of requiring agents to manually search documentation, RAG retrieves relevant articles and generates a summarized answer.

Benefits:

  • Faster issue resolution
  • Improved customer satisfaction
  • Reduced training requirements
  • Consistent troubleshooting guidance

3. Technical Documentation Assistants

Software vendors publish extensive documentation.

Example:

“How do I configure Transparent Data Encryption?”

RAG retrieves:

  • Product documentation
  • Configuration guides
  • Best practices

The LLM produces a concise explanation grounded in the documentation.


4. SQL Database Assistants

Database developers may ask:

  • Explain this stored procedure.
  • Which table stores customer addresses?
  • Show the indexing strategy.
  • What permissions exist on this database?

A RAG system retrieves schema information, documentation, and metadata before generating responses.


5. Help Desk Automation

IT departments frequently answer repetitive questions.

Examples:

  • Password resets
  • VPN setup
  • Printer installation
  • Software installation
  • MFA enrollment

RAG enables intelligent self-service portals.


6. Legal Research

Law firms manage:

  • Contracts
  • Regulations
  • Case law
  • Internal legal guidance

RAG retrieves relevant documents before generating summaries.

Benefits:

  • Faster legal research
  • Improved consistency
  • Reduced manual searching

7. Healthcare Knowledge Systems

Healthcare organizations maintain:

  • Clinical guidelines
  • Treatment protocols
  • Internal procedures

RAG retrieves the latest guidance to support clinicians while ensuring answers are based on approved information.


8. Financial Services

Financial institutions use RAG for:

  • Compliance documentation
  • Regulatory guidance
  • Investment research
  • Internal policies

Because regulations change frequently, RAG provides more current information than relying solely on a model’s training data.


9. Product Recommendation Systems

Instead of searching manually through product catalogs:

Customer asks:

“I’m looking for a waterproof hiking backpack.”

RAG retrieves product specifications before the LLM generates recommendations.


10. Research Assistants

Researchers query:

  • Scientific papers
  • Internal reports
  • Publications
  • Technical documents

RAG retrieves relevant documents and summarizes findings.


Industry Examples

IndustryExample RAG Use Case
HealthcareClinical guideline assistant
BankingRegulatory compliance assistant
InsurancePolicy document assistant
ManufacturingEquipment maintenance assistant
RetailProduct recommendation assistant
EducationCourse material assistant
GovernmentCitizen information portal
LegalContract and legal research assistant
TechnologyDocumentation chatbot
Human ResourcesEmployee policy assistant

When RAG Is NOT Necessary

RAG is not the best solution for every AI application.

Examples where RAG may not be required include:

  • Creative writing
  • Brainstorming ideas
  • Poetry generation
  • Fiction writing
  • General conversations
  • Language translation
  • Grammar correction

These tasks rely primarily on the language capabilities of the LLM rather than external knowledge.


RAG vs Fine-Tuning

A common exam topic is distinguishing RAG from fine-tuning.

RAGFine-Tuning
Retrieves external informationModifies model weights
Uses current dataLearns from training data
No retraining required for document updatesRequires retraining for new knowledge
Best for dynamic informationBest for changing model behavior
Uses databases and documentsUses training datasets

Example:

Company updates its vacation policy.

With RAG:

Simply update the knowledge base.

With fine-tuning:

The model would need to be retrained to incorporate the new policy.


Benefits of RAG

Current Information

Answers reflect the latest available documents.


Reduced Hallucinations

The LLM is grounded with trusted information before generating responses.


Organization-Specific Knowledge

Private business data remains outside the foundation model and is retrieved only when needed.


No Model Retraining

Updating documents updates the knowledge available to the system.


Better Accuracy

Responses are based on authoritative content rather than the model’s memory.


Explainability

Many RAG systems cite or link to the documents used to generate responses.


Limitations of RAG

Dependent on Retrieval Quality

Poor retrieval leads to poor responses.


Requires Search Infrastructure

Organizations must maintain:

  • Embeddings
  • Vector indexes
  • Search indexes
  • Metadata
  • Documents

Additional Latency

Searching for documents adds time before the LLM generates a response.


Token Limits

Too many retrieved documents may exceed the LLM’s context window.

Systems typically retrieve only the most relevant documents.


Selecting Good RAG Use Cases

Ideal RAG scenarios include:

  • Large document collections
  • Frequently changing information
  • Private organizational knowledge
  • Regulatory documentation
  • Technical documentation
  • Search-heavy workloads
  • Question-answering systems

Less suitable scenarios include:

  • Pure text generation
  • Entertainment applications
  • Creative storytelling
  • Static knowledge with no need for external sources

RAG in SQL-Based AI Solutions

Modern SQL platforms increasingly support capabilities that enable RAG solutions, including:

  • Vector data types
  • Embedding storage
  • Vector indexes
  • Hybrid search
  • Similarity search
  • Integration with Azure AI services
  • Secure access to structured and unstructured enterprise data

This allows developers to build AI applications that combine relational data with semantic search in a single solution.


Best Practices

  • Use RAG for applications requiring current or organization-specific information.
  • Build high-quality vector indexes and embeddings to improve retrieval accuracy.
  • Combine vector search with keyword search using hybrid search when appropriate.
  • Retrieve only the most relevant documents to stay within LLM context limits.
  • Apply security trimming so users retrieve only documents they are authorized to access.
  • Regularly update embeddings and indexes when source content changes.
  • Monitor retrieval quality using metrics such as precision, recall, and user feedback.
  • Include citations or source references whenever possible to increase trust.

DP-800 Exam Tips

Remember these key points for the exam:

  • RAG retrieves external information before the LLM generates a response.
  • RAG is ideal for organization-specific, frequently changing, or private knowledge.
  • RAG reduces hallucinations by grounding responses in retrieved documents.
  • RAG is commonly used with vector search and hybrid search.
  • RAG differs from fine-tuning because it does not modify the model’s weights.
  • Updating a knowledge base is typically sufficient to provide new information to a RAG system.
  • Common RAG use cases include enterprise search, customer support, technical documentation, compliance, and knowledge management.
  • Strong retrieval quality is essential because poor retrieval leads to poor AI responses.

Practice Exam Questions

Question 1

A company wants an AI assistant that answers employee questions using the latest HR policies stored in an internal document repository.

Which AI architecture is the most appropriate?

A. Fine-tune a language model every time a policy changes.

B. Use Retrieval-Augmented Generation (RAG).

C. Train a new embedding model monthly.

D. Use only keyword search without an LLM.

Answer: B

Explanation:
RAG retrieves the latest HR documents at query time and provides them to the LLM, allowing responses to reflect current policies without retraining the model.


Question 2

Which scenario is the best candidate for implementing a RAG solution?

A. Generating original poetry

B. Creating fictional stories

C. Answering questions using frequently updated product documentation

D. Producing creative marketing slogans

Answer: C

Explanation:
RAG excels when responses depend on current, external, or organization-specific information, such as product documentation that changes over time.


Question 3

Why does RAG generally reduce hallucinations compared to using an LLM alone?

A. It increases the model’s parameter count.

B. It permanently stores retrieved documents inside the model.

C. It grounds responses using relevant retrieved information.

D. It eliminates vector search.

Answer: C

Explanation:
By providing the LLM with relevant documents before response generation, RAG enables the model to base its answers on trusted information instead of relying solely on its training data.


Question 4

A legal firm needs an AI assistant that answers questions using thousands of contracts and regulatory documents that change regularly.

Which solution is most appropriate?

A. Static prompting only

B. Fine-tuning only

C. Rule-based automation

D. Retrieval-Augmented Generation (RAG)

Answer: D

Explanation:
RAG is well suited for dynamic document collections because updated documents become available to the AI system without requiring model retraining.


Question 5

Which statement correctly distinguishes RAG from fine-tuning?

A. RAG modifies the model’s internal weights.

B. Fine-tuning retrieves external documents during every query.

C. RAG retrieves external information at query time, while fine-tuning changes the model through additional training.

D. There is no practical difference between the two approaches.

Answer: C

Explanation:
RAG supplements a model with retrieved context, whereas fine-tuning changes the model’s learned behavior through additional training.


Question 6

A company updates its employee handbook every month.

What is typically required for a RAG solution to use the latest information?

A. Retrain the large language model.

B. Replace the vector database.

C. Update the document repository, regenerate embeddings if needed, and refresh the search index.

D. Reinstall the AI application.

Answer: C

Explanation:
RAG systems rely on current indexed content. When documents change, embeddings and indexes should be refreshed so the retrieval system can locate the updated information.


Question 7

Which use case is generally least appropriate for a RAG implementation?

A. Internal IT help desk assistant

B. Regulatory compliance assistant

C. Technical documentation chatbot

D. Creative short story generation

Answer: D

Explanation:
Creative writing tasks primarily depend on the language generation capabilities of the model and typically do not require retrieval from external knowledge sources.


Question 8

A financial institution wants an AI solution that always references the latest compliance documents before answering user questions.

What is the primary advantage of using RAG?

A. It permanently stores compliance documents inside the LLM.

B. It enables responses based on current external documents without retraining the model.

C. It eliminates the need for search indexes.

D. It automatically fine-tunes the LLM after every document update.

Answer: B

Explanation:
RAG retrieves current compliance documentation during each query, ensuring responses reflect the latest available information while avoiding repeated model retraining.


Question 9

Which technology is most commonly paired with RAG to retrieve semantically relevant documents?

A. Primary key indexes

B. Trigger-based replication

C. Vector search

D. Transaction log backups

Answer: C

Explanation:
Vector search retrieves semantically similar documents using embeddings and is a foundational component of most modern RAG implementations.


Question 10

A database developer is evaluating potential AI projects.

Which project would benefit the most from a RAG architecture?

A. A calculator that performs arithmetic operations

B. A chatbot that answers questions using an organization’s internal SQL documentation and knowledge base

C. A utility that formats SQL code

D. A script that generates random passwords

Answer: B

Explanation:
A chatbot that relies on organization-specific documentation is an ideal RAG use case because it requires access to current, trusted knowledge that is not contained within the LLM’s training data.


Go to the DP-800 Exam Prep Hub main page

Create a prompt by using the sp_invoke_external_rest_endpoint stored procedure (DP-800 Exam Prep)

This post is a part of the DP-800: Developing AI-Enabled Database Solutions Exam Prep Hub.
This topic falls under these sections:
Implement AI capabilities in database solutions (25–30%)
   --> Design and implement retrieval-augmented generation (RAG)
      --> Identify use cases for RAG


Note that there are 10 practice questions (with answers) at the end of each section to help you solidify your knowledge of the material. Also, there are 4 practice tests with 30 questions each available from the hub's main page below the exam topics section.

Introduction

As SQL databases increasingly integrate with AI services, developers can call external REST APIs directly from Transact-SQL (T-SQL). One important capability is the sp_invoke_external_rest_endpoint system stored procedure, which enables SQL code to securely invoke REST endpoints, including AI services such as Azure AI Foundry models, Azure OpenAI Service, and other HTTP-based APIs.

For the DP-800 exam, you should understand how to use this stored procedure to build prompts, send requests to AI models, process responses, and incorporate Retrieval-Augmented Generation (RAG) workflows into SQL applications.


What Is sp_invoke_external_rest_endpoint?

sp_invoke_external_rest_endpoint is a system stored procedure that enables T-SQL code to invoke external REST APIs directly from supported SQL platforms, such as Azure SQL Database and SQL Server 2025 (where supported and configured).

Instead of requiring an application layer to call an external AI service, the database itself can send an HTTPS request and receive the response.

Typical workflow:

T-SQL
sp_invoke_external_rest_endpoint
REST API
AI Model
JSON Response
SQL Processing

This capability allows SQL applications to integrate directly with AI-powered services while keeping business logic close to the data.


Why Use sp_invoke_external_rest_endpoint?

Many AI services expose REST APIs.

Examples include:

  • Azure OpenAI
  • Azure AI Foundry models
  • Azure AI Language
  • Azure AI Translator
  • Azure AI Vision
  • Custom REST APIs
  • Internal enterprise AI services

Using sp_invoke_external_rest_endpoint enables SQL developers to:

  • Generate AI responses
  • Summarize database content
  • Perform sentiment analysis
  • Translate text
  • Classify documents
  • Invoke Retrieval-Augmented Generation (RAG) workflows
  • Call custom enterprise AI services

Role in Retrieval-Augmented Generation (RAG)

In a RAG solution, the database typically performs several tasks:

  1. Retrieve relevant documents.
  2. Build the prompt.
  3. Call the LLM.
  4. Return the grounded response.

Example workflow:

User Question
Vector Search
Retrieve Context
Build Prompt
sp_invoke_external_rest_endpoint
Large Language Model
Grounded Answer

The stored procedure serves as the bridge between SQL and the external AI model.


Components of an AI Request

A typical AI request contains several elements.

Endpoint URL

The REST endpoint specifies where the request is sent.

Examples include:

  • Azure OpenAI endpoint
  • Azure AI Foundry endpoint
  • Internal REST API

HTTP Method

Most AI inference requests use:

POST

because prompt data is sent in the request body.


HTTP Headers

Headers commonly include:

  • Authorization
  • Content-Type
  • API version (when required)
  • Subscription key (for applicable services)

Example:

Content-Type: application/json
Authorization: Bearer <token>

Authentication methods vary by service and may use Microsoft Entra ID (formerly Azure Active Directory), managed identities, or API keys.


JSON Request Body

The request body contains:

  • Prompt
  • System instructions
  • User input
  • Generation parameters

Example:

{
"messages": [
{
"role": "system",
"content": "You are a SQL assistant."
},
{
"role": "user",
"content": "Explain clustered indexes."
}
]
}

The exact JSON schema depends on the AI service being called.


Creating Effective Prompts

Prompt engineering significantly affects AI output quality.

A good prompt should include:

  • Clear instructions
  • Business context
  • Retrieved documents (for RAG)
  • User question
  • Expected output format

Example Prompt Structure

System:
You are an expert SQL assistant.
Context:
<Document retrieved from vector search>
Question:
How do clustered indexes improve performance?
Instructions:
Answer only using the supplied context.

This structure helps reduce hallucinations and produces grounded responses.


Building Prompts in SQL

Developers often assemble prompts dynamically using T-SQL variables.

Conceptually:

DECLARE @Context NVARCHAR(MAX);
DECLARE @Question NVARCHAR(MAX);
SET @Context =
'Clustered indexes store table rows in key order...';
SET @Question =
'Explain clustered indexes.';

The prompt can then be incorporated into the JSON request body before invoking the external endpoint.

Note: The exact JSON construction depends on the target AI service’s REST API.


Example Workflow

A simplified workflow is:

Retrieve Documents
Build Prompt
Create JSON Payload
Call REST Endpoint
Receive JSON Response
Extract Generated Answer

Conceptual Example

The following simplified example illustrates the overall flow. It is not intended to represent every required parameter or authentication option.

EXEC sp_invoke_external_rest_endpoint
@method = 'POST',
@url = 'https://<ai-endpoint>',
@headers = '{"Content-Type":"application/json"}',
@payload = '{"messages":[...]}';

The supported parameters, authentication methods, and payload format depend on the SQL platform and the REST API being invoked.


Using Retrieved Context in RAG

Suppose vector search returns:

Document:

Clustered indexes physically organize rows according to the index key.

User asks:

Why are clustered indexes faster?

Prompt:

Use only the following information:
Clustered indexes physically organize rows according to the index key.
Question:
Why are clustered indexes faster?

This grounded prompt improves response accuracy.


Processing the Response

Most AI services return JSON.

Example (simplified):

{
"choices": [
{
"message": {
"content": "Clustered indexes improve performance because..."
}
}
]
}

SQL applications can use JSON functions such as:

  • OPENJSON
  • JSON_VALUE
  • JSON_QUERY

to extract values from the response.

Example:

SELECT JSON_VALUE(@Response,
'$.choices[0].message.content');

Authentication Considerations

REST endpoints must be secured.

Depending on the service, authentication may use:

  • Microsoft Entra ID
  • Managed Identity
  • API Keys
  • OAuth access tokens

Developers should avoid embedding secrets directly in T-SQL code.

Instead, use secure credential management mechanisms supported by the platform.


Error Handling

Common failures include:

Authentication Errors

Examples:

  • Invalid token
  • Expired credentials
  • Missing permissions

Network Errors

Examples:

  • Endpoint unavailable
  • Timeout
  • DNS failures

Invalid Request

Examples:

  • Incorrect JSON
  • Unsupported parameter
  • Missing required fields

Rate Limiting

Many AI services enforce request limits.

Applications should be designed to handle HTTP responses such as:

  • 429 Too Many Requests

using retry logic with exponential backoff where appropriate.


Performance Considerations

Calling external AI services introduces additional latency.

Factors include:

  • Network communication
  • AI inference time
  • Prompt size
  • Response size
  • Concurrent requests

Large prompts increase:

  • Token usage
  • Response time
  • Cost

Developers should include only the most relevant retrieved context.


Security Best Practices

When invoking external AI services:

  • Use HTTPS endpoints.
  • Authenticate securely using supported identity mechanisms.
  • Protect API credentials.
  • Validate user input before constructing prompts.
  • Avoid exposing confidential information unnecessarily.
  • Apply least-privilege access.
  • Monitor outbound API usage.
  • Log failures for troubleshooting while avoiding logging sensitive prompt content.

Best Practices for Prompt Design

  • Provide clear system instructions.
  • Include only relevant retrieved context.
  • Tell the model to answer using the supplied context.
  • Specify the desired output format.
  • Keep prompts concise to reduce latency and token consumption.
  • Remove duplicate or irrelevant information.
  • Test prompts using realistic business questions.
  • Evaluate responses for accuracy and consistency.

Common RAG Prompt Pattern

A common prompt template includes:

System
Instructions
Retrieved Context
User Question
Expected Response Format

This structure helps produce consistent, grounded responses.


DP-800 Exam Tips

Remember these key points for the exam:

  • sp_invoke_external_rest_endpoint enables T-SQL code to call external REST APIs directly.
  • In RAG solutions, the stored procedure is commonly used after retrieving relevant documents and constructing a grounded prompt.
  • AI requests typically use the HTTP POST method with a JSON payload.
  • Prompt quality directly influences response quality.
  • Include retrieved context to reduce hallucinations.
  • Responses from AI services are typically returned as JSON and can be parsed using SQL JSON functions.
  • Secure authentication is essential; avoid hard-coding credentials.
  • Minimize prompt size to improve performance and reduce token costs.

Practice Exam Questions

Question 1

A developer wants to call an Azure AI model directly from T-SQL without writing application code.

Which SQL capability enables this functionality?

A. sp_execute_external_script

B. OPENROWSET

C. sp_invoke_external_rest_endpoint

D. BULK INSERT

Answer: C

Explanation:
sp_invoke_external_rest_endpoint enables supported SQL platforms to invoke external REST APIs directly from T-SQL, making it suitable for integrating AI services.


Question 2

In a Retrieval-Augmented Generation (RAG) solution, when is sp_invoke_external_rest_endpoint typically called?

A. Before documents are retrieved.

B. After relevant context has been retrieved and incorporated into the prompt.

C. Before embeddings are generated.

D. Before the vector index is created.

Answer: B

Explanation:
In a typical RAG workflow, relevant documents are first retrieved using vector or hybrid search. The retrieved context is then included in the prompt before calling the LLM through the REST endpoint.


Question 3

Which HTTP method is most commonly used when invoking an AI chat completion REST endpoint?

A. GET

B. DELETE

C. PUT

D. POST

Answer: D

Explanation:
AI inference requests generally send prompts and parameters within the request body, making POST the standard HTTP method.


Question 4

What is the primary benefit of including retrieved documents in the prompt sent to an AI model?

A. It permanently trains the language model.

B. It reduces network latency.

C. It grounds the response using relevant information.

D. It compresses the prompt.

Answer: C

Explanation:
Including retrieved context allows the model to generate responses based on trusted information, improving accuracy and reducing hallucinations.


Question 5

Which SQL functionality is commonly used to extract generated text from a JSON response returned by an AI service?

A. JSON_VALUE

B. MERGE

C. PIVOT

D. ROW_NUMBER

Answer: A

Explanation:
Functions such as JSON_VALUE, JSON_QUERY, and OPENJSON enable SQL developers to parse JSON responses returned by REST APIs.


Question 6

A developer is designing prompts for an AI-powered SQL assistant.

Which prompt design practice generally produces the most reliable responses?

A. Include unrelated historical data to provide additional context.

B. Keep prompts vague so the model has more flexibility.

C. Provide clear instructions and include only relevant retrieved context.

D. Omit the user’s question whenever possible.

Answer: C

Explanation:
Clear instructions and focused, relevant context help the model generate accurate, grounded, and consistent responses.


Question 7

Which authentication approach is recommended when calling secured AI REST endpoints from SQL?

A. Store API keys directly in every stored procedure.

B. Use supported secure authentication mechanisms such as Microsoft Entra ID or managed identities where available.

C. Disable authentication during development and production.

D. Send credentials as query-string parameters.

Answer: B

Explanation:
Secure authentication methods reduce the risk of credential exposure and align with security best practices for accessing external services.


Question 8

What is a common consequence of including excessive retrieved content in a prompt?

A. Lower token usage.

B. Faster inference times.

C. Reduced storage requirements.

D. Increased latency and higher token consumption.

Answer: D

Explanation:
Longer prompts require more tokens to process, increasing inference time, cost, and the likelihood of exceeding the model’s context window.


Question 9

A database application receives an HTTP 429 response from an AI REST endpoint.

What does this response typically indicate?

A. The JSON response is malformed.

B. Authentication failed.

C. The request exceeded the service’s rate limit.

D. The endpoint only accepts GET requests.

Answer: C

Explanation:
HTTP 429 (“Too Many Requests”) indicates that the client has exceeded the allowed request rate. Applications should implement appropriate retry strategies.


Question 10

Which sequence best represents a typical RAG workflow implemented from SQL?

A. Generate response → Retrieve documents → Build prompt → Parse JSON

B. Retrieve documents → Build prompt → Invoke sp_invoke_external_rest_endpoint → Parse the JSON response

C. Create vector index → Generate embeddings → Train the LLM

D. Build prompt → Delete vector index → Generate embeddings

Answer: B

Explanation:
A typical SQL-based RAG workflow retrieves relevant documents, constructs a grounded prompt, invokes the external AI service using sp_invoke_external_rest_endpoint, and then parses the returned JSON response for use by the application.


Go to the DP-800 Exam Prep Hub main page

Convert structured data to JSON for language model processing (DP-800 Exam Prep)

This post is a part of the DP-800: Developing AI-Enabled Database Solutions Exam Prep Hub.
This topic falls under these sections:
Implement AI capabilities in database solutions (25–30%)
   --> Design and implement retrieval-augmented generation (RAG)
      --> Convert structured data to JSON for language model processing


Note that there are 10 practice questions (with answers) at the end of each section to help you solidify your knowledge of the material. Also, there are 4 practice tests with 30 questions each available from the hub's main page below the exam topics section.

Introduction

Modern AI-enabled database applications frequently need to send structured data stored in relational tables to Large Language Models (LLMs). Because LLMs interact with text or structured payloads such as JSON rather than relational tables, developers must transform SQL query results into JSON before sending them to AI services.

For the DP-800 exam, you should understand how to convert relational data into JSON using SQL, why JSON is the preferred interchange format for AI services, how JSON is used in Retrieval-Augmented Generation (RAG) workflows, and the best practices for preparing structured data for language model processing.


Why Convert Structured Data to JSON?

Relational databases organize information into:

  • Tables
  • Rows
  • Columns
  • Relationships

Large Language Models, however, consume:

  • Natural language
  • JSON documents
  • API payloads
  • Structured text

JSON (JavaScript Object Notation) provides a lightweight, hierarchical format that is easy for applications, APIs, and AI models to process.

Instead of sending an entire table, developers typically send only the relevant records formatted as JSON.


Role of JSON in AI Applications

JSON serves as the common data exchange format between SQL databases and AI services.

Typical workflow:

SQL Database
Query Structured Data
Convert to JSON
Build AI Prompt
REST API Request
Large Language Model
AI Response

This process allows structured business data to become part of an AI prompt or API request.


What Is JSON?

JSON is a text-based format consisting of key-value pairs and arrays.

Example:

{
"CustomerID": 1001,
"CustomerName": "Contoso Ltd.",
"Country": "USA",
"CreditLimit": 50000
}

Nested objects are also supported.

Example:

{
"OrderID": 1055,
"Customer": {
"Name": "Contoso Ltd.",
"Country": "USA"
}
}

Hierarchical structures like these are easier for language models to interpret than tabular data.


Why AI Models Prefer JSON

JSON provides several advantages:

  • Human-readable
  • Machine-readable
  • Structured
  • Flexible
  • Widely supported
  • Easily serialized
  • Easily parsed

Most AI REST APIs accept JSON request bodies and return JSON responses.


Converting SQL Query Results to JSON

Modern SQL platforms support generating JSON directly from query results.

For example, SQL Server and Azure SQL Database provide the FOR JSON clause.

Example:

SELECT CustomerID,
CustomerName,
Country
FROM Customers
FOR JSON AUTO;

Sample output:

[
{
"CustomerID":1001,
"CustomerName":"Contoso Ltd.",
"Country":"USA"
},
{
"CustomerID":1002,
"CustomerName":"Fabrikam",
"Country":"Canada"
}
]

This JSON can be incorporated into prompts or REST API requests.


FOR JSON AUTO

FOR JSON AUTO automatically generates JSON based on the structure of the SELECT statement.

Advantages:

  • Minimal configuration
  • Quick generation
  • Good for simple queries

Example:

SELECT ProductID,
ProductName,
Price
FROM Products
FOR JSON AUTO;

FOR JSON PATH

FOR JSON PATH provides greater control over the resulting JSON structure.

Example:

SELECT
CustomerID AS 'Customer.ID',
CustomerName AS 'Customer.Name'
FOR JSON PATH;

Output:

[
{
"Customer": {
"ID":1001,
"Name":"Contoso Ltd."
}
}
]

FOR JSON PATH is preferred when a specific JSON schema is required by an application or AI service.


Creating Nested JSON

Nested JSON is useful for representing parent-child relationships.

Example:

Customer

Orders

Order Items

Instead of returning multiple unrelated tables, developers can build a hierarchical JSON document that mirrors the business object.

This format is often easier for an LLM to understand.


Using JSON in Prompts

Rather than embedding raw SQL results, developers can include JSON as structured context.

Example prompt:

Use the following customer information:
{
"CustomerID":1001,
"Name":"Contoso Ltd.",
"Country":"USA",
"CreditLimit":50000
}
Summarize the customer's profile.

The structured format enables the model to identify fields and values more reliably.


JSON in Retrieval-Augmented Generation (RAG)

In RAG applications, retrieved information often comes from:

  • SQL queries
  • Vector search
  • Hybrid search
  • APIs

Structured query results can be converted to JSON before being added to the prompt.

Workflow:

SQL Query
FOR JSON
Prompt Construction
LLM
Grounded Response

Combining Structured and Unstructured Data

Many AI applications combine relational data with documents.

Example:

Structured data:

{
"OrderID":1055,
"Status":"Shipped"
}

Retrieved documentation:

Orders typically arrive within three business days after shipment.

Prompt:

Order Information:
{
"OrderID":1055,
"Status":"Shipped"
}
Documentation:
Orders typically arrive within three business days.
Answer the customer's question.

This approach gives the LLM access to both factual business data and supporting context.


Reducing Token Usage

Large JSON payloads increase:

  • Prompt size
  • Latency
  • API cost
  • Token consumption

Best practice:

Include only relevant fields.

Instead of:

{
"CustomerID":1001,
"Name":"Contoso",
"Country":"USA",
"Phone":"...",
"Fax":"...",
"CreatedDate":"...",
"LastLogin":"...",
...
}

Use:

{
"CustomerID":1001,
"Country":"USA",
"CreditLimit":50000
}

Only include information required to answer the user’s question.


Security Considerations

Before converting SQL data to JSON:

  • Remove sensitive columns.
  • Exclude personally identifiable information (PII) unless required and authorized.
  • Apply row-level security (RLS).
  • Enforce column-level permissions.
  • Mask confidential values when appropriate.
  • Validate user authorization before retrieving data.

AI models should receive only the data necessary to perform the requested task.


Data Quality Considerations

Language model responses are only as good as the input data.

Ensure that:

  • Missing values are handled appropriately.
  • Duplicate rows are removed.
  • Invalid records are excluded.
  • Data types are consistent.
  • Field names are meaningful.
  • JSON is well-formed and valid.

Poor-quality JSON often leads to inaccurate or confusing AI responses.


Processing AI Responses

Most AI services also return JSON.

Example:

{
"summary":
"Contoso Ltd. is a U.S. customer with a credit limit of $50,000."
}

SQL JSON functions such as:

  • JSON_VALUE
  • JSON_QUERY
  • OPENJSON

can extract values from the response for further processing or storage.


Common Mistakes

Sending Entire Tables

Avoid sending unnecessary rows.

Instead:

Retrieve only relevant records.


Including Too Many Columns

Large prompts increase token usage and cost.


Using Poor Field Names

Prefer:

CustomerName

instead of:

C_Name

Clear field names help improve model understanding.


Ignoring Security

Never expose confidential information unnecessarily.


Creating Invalid JSON

Malformed JSON causes REST API failures and prevents AI services from processing requests.


Best Practices

  • Use FOR JSON AUTO for simple JSON generation.
  • Use FOR JSON PATH when custom JSON structures are required.
  • Return only relevant rows and columns.
  • Keep JSON concise to reduce token consumption.
  • Use meaningful field names.
  • Remove confidential or unnecessary information.
  • Validate JSON before sending it to AI services.
  • Combine structured JSON with retrieved documents for RAG scenarios.
  • Parse AI responses using SQL JSON functions.
  • Test prompts using realistic business data.

DP-800 Exam Tips

Remember these key points for the exam:

  • JSON is the standard format for exchanging structured data with AI services.
  • SQL Server and Azure SQL Database support JSON generation using FOR JSON.
  • FOR JSON AUTO automatically formats query results.
  • FOR JSON PATH provides greater control over JSON structure.
  • RAG solutions often include JSON generated from SQL queries as contextual information.
  • Smaller, focused JSON payloads reduce token usage and improve performance.
  • Protect sensitive information before converting data to JSON.
  • SQL JSON functions can parse AI responses returned as JSON.

Practice Exam Questions

Question 1

A database developer needs to send customer records from SQL Server to a Large Language Model through a REST API.

Which format is most appropriate?

A. XML

B. CSV

C. JSON

D. Binary data

Answer: C

Explanation:
JSON is the standard format accepted by most AI REST APIs because it is lightweight, structured, and easy for both applications and language models to process.


Question 2

Which SQL clause automatically converts query results into JSON using the default structure of the SELECT statement?

A. FOR JSON AUTO

B. FOR XML

C. OPENJSON

D. JSON_VALUE

Answer: A

Explanation:
FOR JSON AUTO automatically generates JSON based on the query structure with minimal configuration.


Question 3

A developer needs complete control over the hierarchy and property names in the generated JSON document.

Which SQL feature should be used?

A. FOR XML

B. FOR JSON PATH

C. JSON_QUERY

D. OPENJSON

Answer: B

Explanation:
FOR JSON PATH allows developers to customize the JSON structure, including nested objects and property names.


Question 4

Why is JSON commonly used when interacting with Large Language Models?

A. It permanently stores embeddings.

B. It replaces vector indexes.

C. It provides a structured, machine-readable format that AI services commonly accept.

D. It automatically encrypts database records.

Answer: C

Explanation:
JSON is widely supported by REST APIs and AI services, making it the preferred format for exchanging structured data.


Question 5

In a Retrieval-Augmented Generation (RAG) solution, why might structured SQL query results be converted to JSON?

A. To include structured business data as context in the prompt sent to the language model.

B. To train the language model.

C. To replace vector embeddings.

D. To eliminate REST APIs.

Answer: A

Explanation:
Structured SQL data converted to JSON can be included in the prompt, allowing the LLM to generate grounded responses using current business information.


Question 6

A developer includes every column from a customer table in the JSON payload, even though only two fields are required.

What is the most likely consequence?

A. Improved retrieval accuracy.

B. Lower API costs.

C. Increased prompt size, token consumption, and latency.

D. Automatic JSON compression.

Answer: C

Explanation:
Sending unnecessary data increases the size of the prompt, which leads to higher token usage, longer response times, and increased cost.


Question 7

Which SQL functions are commonly used to extract values from a JSON response returned by an AI service?

A. ROW_NUMBER and MERGE

B. JSON_VALUE, JSON_QUERY, and OPENJSON

C. PIVOT and UNPIVOT

D. STRING_AGG and GROUP BY

Answer: B

Explanation:
SQL Server provides JSON functions such as JSON_VALUE, JSON_QUERY, and OPENJSON for parsing JSON documents and extracting data.


Question 8

Which practice best improves both security and efficiency when preparing JSON for an AI service?

A. Include every available database column.

B. Return the entire table regardless of the user’s request.

C. Remove unnecessary and sensitive information before generating JSON.

D. Convert the JSON into XML before sending it.

Answer: C

Explanation:
Limiting the JSON payload to only necessary, authorized data reduces token usage, improves performance, and protects sensitive information.


Question 9

What is the primary advantage of using nested JSON structures?

A. They reduce the need for SQL joins.

B. They represent hierarchical relationships in a format that is easier for applications and language models to interpret.

C. They automatically generate embeddings.

D. They eliminate the need for REST APIs.

Answer: B

Explanation:
Nested JSON naturally represents parent-child relationships, making complex business objects easier for both applications and AI models to process.


Question 10

A database application receives a JSON response from an AI service.

What is the next step if the application needs to store the generated summary in a SQL table?

A. Convert the JSON to XML.

B. Rebuild the vector index.

C. Parse the JSON response using SQL JSON functions and extract the required value.

D. Generate new embeddings for the response.

Answer: C

Explanation:
After receiving a JSON response, SQL functions such as JSON_VALUE or OPENJSON can extract the generated content for storage or further processing.


Go to the DP-800 Exam Prep Hub main page

Send results to a language model (DP-800 Exam Prep)

This post is a part of the DP-800: Developing AI-Enabled Database Solutions Exam Prep Hub.
This topic falls under these sections:
Implement AI capabilities in database solutions (25–30%)
   --> Design and implement retrieval-augmented generation (RAG)
      --> Send results to a language model


Note that there are 10 practice questions (with answers) at the end of each section to help you solidify your knowledge of the material. Also, there are 4 practice tests with 30 questions each available from the hub's main page below the exam topics section.

Introduction

One of the final steps in a Retrieval-Augmented Generation (RAG) workflow is sending retrieved data to a Large Language Model (LLM). After retrieving relevant information from a SQL database, vector index, or hybrid search system, the application packages the data into a prompt and submits it to an AI model through a REST API. The quality of this process directly affects the accuracy, relevance, security, and efficiency of the generated response.

For the DP-800 exam, you should understand how to prepare retrieved results for language model processing, construct effective prompts, submit requests to AI services, handle responses, and follow best practices for security, performance, and reliability.


Where This Step Fits in a RAG Workflow

A Retrieval-Augmented Generation solution consists of several stages.

User Question
Generate Query Embedding
Vector or Hybrid Search
Retrieve Relevant Documents
Prepare Context
Build Prompt
Send Request to Language Model
Receive AI Response
Return Answer to User

Sending the retrieved results to the language model is the bridge between the retrieval system and the AI model.


Why Send Retrieved Results?

Large Language Models do not automatically have access to:

  • SQL databases
  • Internal documentation
  • Company policies
  • Product catalogs
  • Customer records
  • Knowledge bases

Instead, developers retrieve the necessary information and include it in the prompt sent to the model.

This process grounds the AI response in trusted, current information.


Components of a Request

A typical request sent to a language model includes several elements.

System Instructions

The system message defines the model’s role and behavior.

Example:

You are an expert SQL database assistant.
Answer only using the supplied context.

System instructions establish the rules the model should follow.


Retrieved Context

The retrieved context contains the information found during vector or hybrid search.

Example:

Document:
Clustered indexes physically store rows according to the index key.

Only relevant context should be included.


User Question

The original user request is included.

Example:

Why do clustered indexes improve query performance?

The language model combines the retrieved context with the user question to generate an answer.


Output Instructions

Developers may specify:

  • Response length
  • Formatting
  • Tone
  • JSON output
  • Markdown output
  • Bullet lists

Example:

Provide a concise answer in three bullet points.

Preparing Retrieved Results

Retrieved documents often require preprocessing before being sent to the model.

Common preprocessing tasks include:

  • Removing duplicate documents
  • Eliminating irrelevant information
  • Trimming excessively long content
  • Combining related results
  • Filtering unauthorized information
  • Formatting structured data as JSON when appropriate

Proper preparation improves both response quality and efficiency.


Selecting Relevant Context

Sending too much information can reduce answer quality and increase cost.

Best practice:

Retrieve only the top-ranking documents.

For example:

Instead of sending:

  • 50 documents

Send:

  • Top 3–10 highly relevant documents

The exact number depends on the application’s requirements and the model’s context window.


Structuring the Prompt

A well-organized prompt improves response quality.

A common structure is:

System Instructions
Retrieved Context
User Question
Expected Response Format

Example:

You are a SQL expert.
Context:
Clustered indexes physically organize table rows according to the key.
Question:
Why do clustered indexes improve query performance?
Answer only using the provided context.

Sending Structured Data

Sometimes the retrieved information is relational data rather than documents.

Example SQL output:

CustomerCountryCredit Limit
ContosoUSA50000

Instead of sending the table directly, developers often convert it to JSON.

Example:

{
"Customer":"Contoso",
"Country":"USA",
"CreditLimit":50000
}

JSON provides a structured format that AI services process efficiently.


Calling the Language Model

Most AI services expose REST APIs.

A request typically includes:

  • HTTPS endpoint
  • HTTP POST method
  • Authentication
  • JSON payload

Conceptually:

Prompt
JSON Request
REST API
Language Model
JSON Response

SQL Server and Azure SQL Database can call supported REST endpoints using the sp_invoke_external_rest_endpoint stored procedure where available.


Processing the Response

Most AI services return JSON.

Example:

{
"choices":[
{
"message":{
"content":"Clustered indexes improve performance because..."
}
}
]
}

SQL applications can extract the generated text using JSON functions such as:

  • JSON_VALUE
  • JSON_QUERY
  • OPENJSON

The application can then display, store, or further process the generated response.


Managing Context Windows

Every language model has a maximum context window.

The context window includes:

  • System instructions
  • Retrieved documents
  • User question
  • Previous conversation
  • Generated response

If too much information is included, requests may fail or important information may be truncated.

Developers should:

  • Remove irrelevant content.
  • Retrieve fewer documents.
  • Summarize long documents.
  • Limit prompt size.

Token Usage

Language models process text as tokens.

More retrieved content means:

  • More input tokens
  • Longer inference time
  • Higher API costs
  • Increased latency

Reducing unnecessary context improves both performance and cost efficiency.


Security Considerations

Developers should never send sensitive information unnecessarily.

Examples include:

  • Passwords
  • Authentication secrets
  • Personal identifiers
  • Confidential financial records
  • Protected health information
  • Internal security credentials

Before sending data to an external AI service:

  • Apply row-level security (RLS).
  • Apply column-level security.
  • Remove confidential fields.
  • Mask sensitive values when appropriate.
  • Verify user authorization.

Grounding the Response

One of the primary goals of RAG is grounding.

Grounding means that the model bases its answer on retrieved information rather than relying solely on its internal training.

Example instruction:

Answer only using the supplied documents.
If the answer is unavailable, say you do not know.

This helps reduce hallucinations.


Handling Errors

Common issues include:

Authentication Failures

Examples:

  • Expired tokens
  • Invalid credentials
  • Missing permissions

Network Problems

Examples:

  • Endpoint unavailable
  • Timeouts
  • DNS failures

Rate Limits

AI services may return:

429 Too Many Requests

Applications should implement retry logic using exponential backoff.


Invalid Requests

Examples:

  • Malformed JSON
  • Missing prompt
  • Unsupported parameters

Performance Considerations

Factors affecting performance include:

  • Prompt size
  • Number of retrieved documents
  • Network latency
  • AI model size
  • Token count
  • Response length
  • Concurrent requests

Performance can often be improved by:

  • Sending fewer documents.
  • Using concise prompts.
  • Removing duplicate information.
  • Optimizing retrieval quality.

Common Mistakes

Sending Irrelevant Documents

The language model may generate inaccurate or confusing responses.


Including Entire Database Records

Large prompts increase token usage and cost.


Poor Prompt Design

Ambiguous instructions often produce inconsistent responses.


Ignoring Security

Sensitive information should never be included unless necessary and authorized.


Missing Grounding Instructions

Without guidance, the model may rely on general knowledge instead of retrieved context.


Best Practices

  • Retrieve only the most relevant documents.
  • Use clear system instructions.
  • Include the user’s original question.
  • Organize prompts consistently.
  • Limit prompt size to reduce token usage.
  • Convert structured data to JSON when appropriate.
  • Remove sensitive information before sending requests.
  • Validate JSON payloads.
  • Monitor latency and token consumption.
  • Evaluate AI responses for accuracy and relevance.

Real-World Example

A company stores warranty information in SQL Server.

Workflow:

  1. Customer asks:”Is my laptop still under warranty?”
  2. SQL retrieves:
Product: X500
Purchase Date: January 10, 2025
Warranty: 2 Years
  1. JSON is generated:
{
"Product":"X500",
"PurchaseDate":"2025-01-10",
"Warranty":"2 Years"
}
  1. Prompt sent to the language model:
Use the following warranty information:
{
"Product":"X500",
"PurchaseDate":"2025-01-10",
"Warranty":"2 Years"
}
Answer whether the warranty is still valid.

The language model generates a grounded response using the supplied business data.


DP-800 Exam Tips

Remember these key points for the exam:

  • Sending results to the language model is the final step before AI response generation in a RAG workflow.
  • Retrieved documents should be relevant, concise, and properly formatted.
  • System instructions help guide model behavior.
  • Structured SQL data is often converted to JSON before being included in prompts.
  • Smaller prompts reduce latency and token costs.
  • Grounding instructions help reduce hallucinations.
  • Responses from AI services are typically returned as JSON.
  • Sensitive information should be removed before sending requests to external AI services.

Practice Exam Questions

Question 1

A developer is building a Retrieval-Augmented Generation (RAG) application.

After retrieving relevant documents from a vector search, what is the next logical step?

A. Send the retrieved context to the language model as part of the prompt.

B. Retrain the language model.

C. Rebuild the vector index.

D. Delete duplicate embeddings.

Answer: A

Explanation:
After retrieval, the relevant documents are incorporated into the prompt and sent to the language model so it can generate a grounded response.


Question 2

Why should retrieved documents be included in a prompt sent to a language model?

A. To permanently update the model’s training data.

B. To ground the model’s response using relevant information.

C. To reduce embedding dimensions.

D. To replace vector indexes.

Answer: B

Explanation:
Including retrieved context enables the model to generate responses based on current, authoritative information rather than relying solely on pre-trained knowledge.


Question 3

Which prompt component defines the behavior the language model should follow?

A. Retrieved context

B. User question

C. System instructions

D. JSON response

Answer: C

Explanation:
System instructions establish the role, behavior, and constraints for the language model, such as answering only from the supplied context.


Question 4

A developer sends fifty retrieved documents to a language model, even though only five are relevant.

What is the most likely consequence?

A. Improved grounding accuracy.

B. Reduced API costs.

C. Faster inference.

D. Increased token usage, latency, and potential reduction in response quality.

Answer: D

Explanation:
Including excessive context increases prompt size, consumes more tokens, raises costs, and may dilute the relevance of the information presented to the model.


Question 5

Which format is commonly used to send structured SQL query results to a language model?

A. Binary

B. XML

C. JSON

D. CSV

Answer: C

Explanation:
JSON is the standard format for exchanging structured data with AI services because it is lightweight, hierarchical, and widely supported.


Question 6

What is the primary purpose of grounding instructions such as “Answer only using the supplied context”?

A. Increase the embedding dimension.

B. Reduce hallucinations by limiting the model to retrieved information.

C. Eliminate authentication requirements.

D. Automatically compress prompts.

Answer: B

Explanation:
Grounding instructions encourage the model to base its responses on the retrieved documents instead of relying on unsupported assumptions or prior training.


Question 7

A language model returns its response as JSON.

Which SQL functions can be used to extract the generated answer?

A. MERGE and GROUP BY

B. ROW_NUMBER and RANK

C. STRING_AGG and PIVOT

D. JSON_VALUE, JSON_QUERY, and OPENJSON

Answer: D

Explanation:
SQL Server provides JSON functions that allow applications to parse AI responses and extract specific values from JSON documents.


Question 8

Which security practice is most appropriate before sending retrieved results to an external AI service?

A. Include every available column to maximize context.

B. Remove sensitive or unauthorized information from the retrieved data.

C. Disable row-level security.

D. Send authentication credentials within the prompt.

Answer: B

Explanation:
Only the information necessary for the AI task should be sent. Sensitive data should be removed or masked, and normal security controls should remain in effect.


Question 9

Why is prompt size an important consideration when sending results to a language model?

A. Larger prompts always improve response quality.

B. Prompt size has no effect on AI services.

C. Larger prompts increase token usage, cost, and response latency.

D. Prompt size determines the embedding algorithm.

Answer: C

Explanation:
Every token contributes to processing time and cost. Keeping prompts concise improves performance while reducing API expenses.


Question 10

A company wants an AI assistant to answer questions using current warranty information stored in SQL Server.

Which approach best supports this requirement?

A. Fine-tune the language model every time warranty records change.

B. Store warranty records directly inside the model.

C. Build a RAG workflow that retrieves the current warranty data, formats it appropriately, and sends it to the language model.

D. Disable retrieval and rely only on the model’s training data.

Answer: C

Explanation:
A RAG solution retrieves current business data at query time, formats it (often as JSON), and sends it to the language model, allowing responses to remain accurate without requiring model retraining.


Go to the DP-800 Exam Prep Hub main page