symfony/ai

"I don't know yet what I'm talking about – but I'm very excited about it"

Johannes Wachter

VLBGWebDev | 18.03.2026

Enhanced RAG: Beyond Hello World

From Vector Search to Production-Ready Knowledge Retrieval

Sound Familiar?

Ask: "How do I send emails in my PHP app?"

Naive RAG Result:

  • Returns docs about the deprecated mail() function
  • Mixes up SwiftMailer (abandoned) with Symfony Mailer
  • Context window overloaded with irrelevant docs

"Embedding + Vector Store" – sounds simple, but it's just the beginning.

profile-image

Hi, I'm Johannes Wachter

  • Core Developer at Sulu CMS & Creator of ModelflowAI
  • Currently bringing ModelflowAI ideas & code into symfony/ai
  • Works with Symfony since 2012
  • Lecturer at University of Applied Science Dornbirn
  • Open Source & AI Enthusiast
  • Father of two

My Work in symfony/ai

Area Contributions
AI Mate MCP server for debugging & developing PHP/Symfony apps – creator & maintainer
Store Query abstractions, hybrid retrieval, reranking
Platform Prompt templates, structured output

The examples in this talk are based on real PRs in symfony/ai from the last 3 weeks.

Live Demo: Naive RAG

  • Querying Symfony docs with basic vector search
  • See where simple "embed + retrieve" breaks down
  • Outdated results, missing context, wrong ranking

Problem: Semantic Gap & Ambiguity

User writes: "how do i set up auth"

  • Ambiguous: JWT? OAuth? Symfony Security?
  • Implicit: Version? Bundle? Stack?
  • Vector search finds "email validation" when you ask "send email"

The retriever doesn't understand the question.

Solution: Query Analysis

"how do i set up auth"
Query Analysis / Rewrite (intent, entities, expansion)
"Symfony 7 JWT authentication configuration tutorial"

Techniques

  • Query Rewriting – expand abbreviations, add context, fix typos
  • Intent Classification – documentation vs. troubleshooting vs. comparison
  • Entity Extraction – framework, version, topic

Live Coding: Add Query Analysis

  • Add query rewriting to the pipeline
  • See how results improve with better query understanding

Problem: Keyword Blindness

  • Vector search misses exact matches like "Mailer" or "security.yaml"
  • Semantic similarity alone isn't enough
  • You need both meaning and exact terms

Vector search finds similar docs – but misses the obvious ones.

Solution: Hybrid Retrieval

Vector Search + Full-Text = Better Together

finds "send email" finds "Mailer"
Vector Search yes no
Full-Text Search no yes
Hybrid (RRF) yes yes

Reciprocal Rank Fusion (RRF)

RRFscore(d)=iRanks1k+ranki(d)

  • d – the document being scored
  • rank_i(d) – position of d in the i-th ranking (starting at 1)
  • k – smoothing parameter (typically 60), prevents low ranks from dominating

Live Coding: Add Hybrid Retrieval

  • Replace pure vector search with hybrid retriever
  • See keyword matches surface alongside semantic results

Problem: Wrong Order

  • Top-K isn't Top-Relevant
  • Mixes SwiftMailer (abandoned) with Symfony Mailer
  • Returns mail() docs alongside modern Mailer docs

We have the right candidates – but in the wrong order.

Solution: Reranking

Two-Stage Architecture

Stage What Cost Relevance
1. Hybrid Search 50–100 candidates cheap ~60%
2. Cross-Encoder Rerank Re-score all candidates expensive ~90%

How It Works

  • A Cross-Encoder takes (query, document) pairs and scores them jointly
  • Unlike embeddings, it sees both texts at once → much more accurate
  • Models: BAAI/bge-reranker-v2-m3 (HuggingFace) · Cohere/rerank-english-v3.0 (Cloud)

Live Coding: Add Reranking

  • Add cross-encoder reranking to the pipeline
  • See outdated and irrelevant docs drop to the bottom

Problem: How Does RAG Reach AI Agents?

How does your RAG pipeline get into Claude/Cursor/VS Code?

Solution: MCP (Model Context Protocol)

  • Your RAG pipeline becomes an MCP Tool
  • AI Agents can "ask" instead of "guess"
┌─────────────┐         ┌─────────────┐
│ Claude /    │ ←──────→ │ MCP Client  │
│ Cursor      │  JSON-RPC│             │
└─────────────┘         └──────┬──────┘
                               │
                               ↓
                      ┌─────────────────┐
                      │ MCP Server      │
                      │ (your app)      │
                      └─────────────────┘

Outlook: ai-mate + Enhanced RAG

MCP server for debugging & developing PHP/Symfony apps

  • Already works: ./bin/mate serve → AI agents get project context
  • Coming soon: search_docs tool with Enhanced RAG (open PR)
  • Goal: Your AI assistant understands your codebase and the docs behind it

Query Analysis + Hybrid Retrieval + Reranking – the full pipeline from this talk, available as MCP tool in Claude/Cursor.

Why symfony/ai?

  • DI, Config, Profiler, Debug Toolbar – 100% Symfony native
  • 10+ LLM providers – OpenAI, Anthropic, Mistral, Ollama, ...
  • 5+ vector stores – Qdrant, Chroma, Pinecone, PostgreSQL, ...
  • Query Analysis, Hybrid Retrieval, Reranking – built-in
  • MCP Server – first-class integration
  • ai-mate – MCP server for debugging & developing PHP/Symfony apps

Resources

  • symfony/ai: github.com/symfony/ai
  • ai-mate: github.com/modelflow-ai/ai-mate
  • MCP: modelcontextprotocol.io
  • HuggingFace: huggingface.co
  • Slides: wachterjohannes.github.io/rag-beyond-hello-world
  • Code: github.com/wachterjohannes/rag-beyond-hello-world

Thank You!

@wachterjohannes