Coding portfolio / AI Engineering
RAG evaluation toolkit
I demonstrate how retrieval precision and recall can be evaluated on a small labelled dataset.
Educational reference implementation · synthetic example
Source code
"""Educational retrieval evaluation example; no production or employer data."""
def evaluate(retrieved, relevant):
retrieved, relevant = list(dict.fromkeys(retrieved)), set(relevant)
hits = sum(x in relevant for x in retrieved)
return {"precision": hits / len(retrieved) if retrieved else 0.0,
"recall": hits / len(relevant) if relevant else 0.0}
if __name__ == "__main__":
example = evaluate(["doc-1", "doc-2", "doc-5"], {"doc-1", "doc-2", "doc-3"})
assert example == {"precision": 2/3, "recall": 2/3}
print(example)
How I approach the implementation
I keep the core logic reproducible, separate test data from implementation and document assumptions before using the approach in production.
Run this example
python rag_evaluation.py
These are illustrative educational samples created for this portfolio, not employer-owned code or production-ready security controls.
LET'S CONNECT
Let’s build something with AI.
I welcome conversations about enterprise AI, strategic advisory, executive leadership and research collaboration.
puneett.bhatnagr@gmail.com- AI engineering and enterprise architecture
- Responsible AI and model risk
- Executive opportunities and consulting
- Research and technical collaboration
TRUSTED AI BY DESIGN