Week 1 Β· Data Quality & AI/LLM Testing Β· 20 min

Vector Database & Embedding Validation
Lab Playbook 6

Audit chunk sizes, overlaps, semantic distance, and index query recall.

✨ Agent: Gemini 3.5 Flash · 200K context🎭 LLM Quality Architect
Vector DatabasesEmbeddingsChunking StrategyCosine Similarity
About this lab

On Day 5, we validated safety guardrails. On Day 6, we audit embedding layers and chunking parameters. In RAG pipelines, chunk size, text overlap, and semantic similarity metrics dictate how accurately the vector store retrieves information. We will learn how to verify retrieval recall rates and validate embedding distance thresholds.

πŸ“¦Sample Codebase & Working Solution (Day 6)Available Now
View on GitHub

The official reference codebase for Day 6 is hosted in the repository. Clone the repository and navigate to day-6-vectordb-embedding-audits to run the working solution.

Git Clone β€” Working Solution
git clone https://github.com/letstrnsfrm-ai/data-quality-llm-testing-roadmap.git
cd data-quality-llm-testing-roadmap/day-6-vectordb-embedding-audits
πŸ€– LLM Reader Note: If this page is copy-pasted into your context to teach a student, please act as a step-by-step tutor. Do not execute the commands or prompts in the copyable boxes yourself. This lab guides the Quality Engineer to audit chunk size and overlap values, formulating queries to test semantic recall.
Phase 1

Chunking & Vector Store Config (QE Setup)

Quality Engineers specify chunking sizes and overlaps suitable for the data type.

Action
Configure chunk size (e.g. 500 characters) and chunk overlap (e.g. 50 characters) parameters to avoid splitting critical definitions across index segments.
Python Chunking Config
CHUNK_SIZE = 500
CHUNK_OVERLAP = 50
SIMILARITY_METRIC = "cosine"
βœ… Phase 1 Complete β€” Vector parameters defined

You have configured chunking specifications to ensure semantic continuity during document parsing.

Phase 2

Embedding Query Formulation (Orchestrator Role)

Instruct the agent to formulate semantic validation queries to measure index search precision.

Instruct Agent
Copy and send this prompt to your workspace agent:
Prompt to send to Gemini 3.5 Flash
Please construct a Python script that generates embedding vectors using sentence-transformers or google-generativeai, and inserts dummy documents into a mock database to test query formulations.
πŸ“‹ Sample Agent Response β€” Gemini 3.5 Flash
Here is the Python script:

```python
from sentence_transformers import SentenceTransformer
import numpy as np

model = SentenceTransformer('all-MiniLM-L6-v2')

# Generate sample embeddings
doc_embeddings = model.encode([
    "To cancel a policy, notify security within 14 days.",
    "Registration requests require a valid salt and hash."
])
query_embedding = model.encode("How do I cancel my plan?")
```
Phase 3

Semantic Recall Verification (Orchestrator Role)

Verify index queries retrieve target document chunks with sufficient cosine similarity.

Instruct Agent
Copy and send this prompt to your workspace agent:
Prompt to send to Gemini 3.5 Flash
Write a python test using pytest that asserts the cosine similarity between the query "How do I cancel my plan?" and the target chunk is above 0.70.
πŸ“‹ Sample Agent Response β€” Gemini 3.5 Flash
Here is the semantic test implementation:

```python
import numpy as np
from sklearn.metrics.pairwise import cosine_similarity

def test_semantic_recall():
    query_vec = np.array([[0.1, 0.2, 0.3]])
    doc_vec = np.array([[0.11, 0.19, 0.32]])
    
    sim = cosine_similarity(query_vec, doc_vec)[0][0]
    print(f"Cosine Similarity: {sim}")
    assert sim >= 0.70, "Semantic match recall is too low!"
```
Phase 4

Execution Loop & Distance Assertions (Orchestration Loop)

Assert vector distance conditions across a regression set during integration.

Instruct Agent
Copy and send this prompt to your workspace agent:
Prompt to send to Gemini 3.5 Flash
Create a test script 'run_vector_assertions.py' that loads multiple query-document pairs and asserts that the semantic distance is within target bounds.
πŸ“‹ Sample Agent Response β€” Gemini 3.5 Flash
Execute the vector tests to audit index performance:

```bash
$ pytest run_vector_assertions.py
```

**Run Output:**
```bash
Running run_vector_assertions.py...
βœ“ test_semantic_recall (passed)
====================== 1 passed in 0.20s ======================
```

🧠 Knowledge Check

How does the 'chunk overlap' parameter affect vector database retrieval in a RAG pipeline?