
Beyond simple RAG: Encoding years of analytical intent and structural patterns into a production-ready knowledge base.
Explore how Pinterest solved the fundamental challenges of natural language data analysis in a massive data warehouse. By treating query history as a library of expert knowledge rather than raw syntax, they've built a system that understands business intent and delivers validated, trustworthy SQL results.
Essential reading for Data Engineers and AI Practitioners looking to deploy production-grade RAG systems in complex enterprise data environments.
Pinterest faced challenges in generating accurate SQL at scale, with over 100,000 tables and thousands of users, where simple keyword matching and basic table summaries failed to capture complex analytical intent. Standard LLM approaches lacked domain-specific context, validated join patterns, and awareness of data governance, leading to unreliable query generation.
The team developed a production Analytics Agent using 'Unified Context-Intent Embeddings' that transform historical SQL queries into natural language business questions enriched with domain context. This was combined with structural/statistical patterns extracted from query logs and a governance-aware ranking system to prioritize trustworthy, high-tier tables during retrieval.
The system became the most widely adopted agent at Pinterest, reducing manual documentation effort by 70% through AI-generated docs and lineage propagation. Over 75% of AI-generated table descriptions were rated as 'usable' or better by human analysts.
Trade-off
The effectiveness of this approach is highly dependent on an established data governance framework (like table tiering) and a rich history of expert queries, suggesting it may not be as effective for organizations with low data maturity or sparse query logs.
A methodology that transforms raw SQL syntax into semantically rich natural language descriptions capturing the underlying business purpose.
A retrieval mechanism that combines semantic search scores with trust signals such as table tiers, data freshness, and documentation quality.
An automated documentation technique that infers column semantics by analyzing how tables are joined in query history.




