How AI Is Built

#018 Query Understanding: Doing The Work Before The Query Hits The Database

How AI Is Built

Show Notes

Welcome back to How AI Is Built. We have got a very special episode to kick off season two. Daniel Tunkelang is a search consultant currently working with Algolia. He is a leader in the field of information retrieval, recommender systems, and AI-powered search. He worked for Canva, Algolia, Cisco, Gartner, Handshake, to pick a few. His core focus is query understanding. **Query understanding is about focusing less on the results and more on the query.** The query of the user is the first-class citizen. It is about figuring out what the user wants and than finding, scoring, and ranking results based on it. So most of the work happens before you hit the database. **Key Takeaways:** - The "bag of documents" model for queries and "bag of queries" model for documents are useful approaches for representing queries and documents in search systems. - Query specificity is an important factor in query understanding. It can be measured using cosine similarity between query vectors and document vectors. - Query classification into broad categories (e.g., product taxonomy) is a high-leverage technique for improving search relevance and can act as a guardrail for query expansion and relaxation. - Large Language Models (LLMs) can be useful for search, but simpler techniques like query similarity using embeddings can often solve many problems without the complexity and cost of full LLM implementations. - Offline processing to enhance document representations (e.g., filling in missing metadata, inferring categories) can significantly improve search quality. **Daniel Tunkelang** - [LinkedIn](https://www.linkedin.com/in/dtunkelang/) - [Medium](https://queryunderstanding.com/) **Nicolay Gerold:** - [⁠LinkedIn⁠](https://www.linkedin.com/in/nicolay-gerold/) - [⁠X (Twitter)](https://twitter.com/nicolaygerold) - [Substack](https://nicolaygerold.substack.com/) Query understanding, search relevance, bag of documents, bag of queries, query specificity, query classification, named entity recognition, pre-retrieval processing, caching, large language models (LLMs), embeddings, offline processing, metadata enhancement, FastText, MiniLM, sentence transformers, visualization, precision, recall [00:00:00] 1. Introduction to Query Understanding Definition and importance in search systems Evolution of query understanding techniques [00:05:30] 2. Query Representation Models The "bag of documents" model for queries The "bag of queries" model for documents Advantages of holistic query representation [00:12:00] 3. Query Specificity and Classification Measuring query specificity using cosine similarity Importance of query classification in search relevance Implementing and leveraging query classifiers [00:19:30] 4. Named Entity Recognition in Query Understanding Role of NER in query processing Challenges with unique or tail entities [00:24:00] 5. Pre-Retrieval Query Processing Importance of early-stage query analysis Balancing computational resources and impact [00:28:30] 6. Performance Optimization Techniques Caching strategies for query understanding Offline processing for document enhancement [00:33:00] 7. Advanced Techniques: Embeddings and Language Models Using embeddings for query similarity Role of Large Language Models (LLMs) in search When to use simpler techniques vs. complex models [00:39:00] 8. Practical Implementation Strategies Starting points for engineers new to query understanding Tools and libraries for query understanding (FastText, MiniLM, etc.) Balancing precision and recall in search systems [00:44:00] 9. Visualization and Analysis of Query Spaces Discussion on t-SNE, UMAP, and other visualization techniques Limitations and alternatives to embedding visualizations [00:47:00] 10. Future Directions and Closing Thoughts - Emerging trends in query understanding - Key takeaways for search system engineers [00:53:00] End of Episode

More from How AI Is Built

Sep 11, 2025

Nicolay here, Most AI coding conversations focus on which model to use. This one focuses on workflow - the specific commands, git strategies, and review processes that let one engineer ship production code with AI agents doing 80% of the work. Today I have the chance to talk to Kieran Klaassen, who built Cora (an AI email management tool) almost entirely solo using AI agents. His approach: treat AI agents like junior developers you manage, not tools you operate. The key insight centers on "compound engineering" - extracting reusable systems from every code review and interaction. Instead of just reviewing pull requests, Kieran records his review sessions with his colleague, transcribes them, and feeds the transcriptions to Claude to extract coding patterns and philosophical approaches into custom slash commands. In the podcast, we also touch on: Git worktrees for running multiple AI agents simultaneously The evolution from Cursor Composer to Claude Code and Friday Why pull request review is the real bottleneck, not code generation How to structure research phases to avoid AI going off the rails and more 💡 Core Concepts Compound Engineering: Extracting reusable systems, SOPs, and taste from every AI interaction - treating each code review or feature build as an opportunity to teach the AI your standards and decision-making patterns. Git Worktrees for AI Agents: Running multiple AI coding agents simultaneously by checking out different branches in separate file system directories, allowing parallel feature development without conflicts. Research-First AI Development: Starting every feature with a dedicated research phase where AI gathers context, explores multiple approaches, and creates detailed GitHub issues before any code is written. Tiered Code Review Systems: Implementing different review checklists and standards based on risk level (payments, migrations, etc.) with AI assistants handling initial passes before human review. 📶 Connect with Kieran: X / Twitter Cora 📶 Connect with Nicolay: Newsletter LinkedIn X / Twitter Bluesky Website My Agency Aisbach (for ai implementations / strategy) ⏱️ Important Moments The Sonnet 3.5 Breakthrough Moment: [09:30] Kieran describes vibe-coding a Swift app in one evening, realizing AI could support solo entrepreneurship for the first time. Building Cora's First Prototype: [12:45] One night to build a prototype that drafts email responses - the moment they knew there was something special about AI handling email. The Nice, France Experiment: [13:40] Testing automatic email archiving while walking around town, discovering the "calm feeling" that became Cora's core value proposition. Git Worktrees Discovery: [50:50] How Kieran discovered worktrees by asking AI for a solution to run multiple agents simultaneously, leading to his current parallel development workflow. Cursor 3.7 Breaking Point: [19:57] The moment Cursor became unusable after shipping too many changes at once, forcing the search for better agentic tools. Friday vs Claude Code Comparison: [22:23] Why Friday's "YOLO mode" and end-to-end pull request creation felt more like having a colleague than using a tool. Compound Engineering Philosophy: [33:18] Recording code review sessions and extracting engineering taste into reusable Claude commands for future development. The Research Phase Strategy: [04:48] Why starting with comprehensive GitHub issue research prevents AI agents from going off-rails during implementation. Pull Request Review Bottleneck: [28:44] How reviewing AI-generated code, not writing it, becomes the main constraint when scaling with agents. Multiple Agent Management: [48:14] Running Claude Code work trees in parallel terminals, treating each agent as a separate team member with distinct tasks. 🛠️ Tools & Tech Mentioned Claude Code Cursor Friday AI Git Worktrees Warp Terminal GitHub CLI Charlie AI (PR review bot) Context7 MCP Anthropic Prompt Improver

Aug 13, 2025

Nicolay here, while everyone races to cloud-scale LLMs, Pete Warden is solving AI problems by going completely offline. No network connectivity required. Today I have the chance to talk to Pete Warden, CEO of Useful Sensors and author of the TinyML book. His philosophy: if you can't explain to users exactly what happens to their data, your privacy model is broken. Key Insight: The Real World Action Gap LLMs excel at text-to-text transformations but fail catastrophically at connecting language to physical actions. There's nothing in the web corpus that teaches a model how "turn on the light" maps to sending a pin high on a microcontroller. This explains why every AI agent demo focuses on booking flights and API calls - those actions are documented in text. The moment you step off the web into real-world device control, even simple commands become impossible without custom training on action-to-outcome data. Pete's company builds speech-to-intent systems that skip text entirely, going directly from audio to device actions using embeddings trained on limited action sets. 💡 Core Concepts Speech-to-Intent: Direct audio-to-action mapping that bypasses text conversion, preserving ambiguity until final classification ML Sensors: Self-contained circuit boards processing sensitive data locally, outputting only simple signals without exposing raw video/audio Embedding-Based Action Matching: Vector representations mapping natural language variations to canonical device actions within constrained domains ⏱ Important Moments Real World Action Problem: [06:27] LLMs discuss turning on lights but lack training data connecting text commands to device control Apple Intelligence Challenges: [04:07] Design-led culture clashes with AI accuracy limitations Speech-to-Intent vs Speech-to-Text: [12:01] Breaking audio into text loses critical ambiguity information Limited Action Set Strategy: [15:30] Smart speakers succeed by constraining to ~3 functions rather than infinite commands 8-Bit Quantization: [33:12] Remains deployment sweet spot - processor instruction support matters more than compression On-Device Privacy: [47:00] Complete local processing provides explainable guarantees vs confusing hybrid systems 🛠 Tools & Tech Whisper: github.com/openai/whisper Moonshine: github.com/usefulsensors/moonshine TinyML Book: oreilly.com/library/view/tinyml/9781492052036 Stanford Edge ML: github.com/petewarden/stanford-edge-ml 📚 Resources Looking to Listen Paper: looking-to-listen.github.io Lottery Ticket Hypothesis: arxiv.org/abs/1803.03635 Connect: [email protected] | petewarden.com | usefulsensors.com Beta Opportunity: Moonshine browser implementation for client-side speech processing in JavaScript

Jul 29, 2025

Nicolay here,most AI conversations focus on training bigger models with more compute. This one explores the counterintuitive world where averaging weights from different models creates better performance than expensive post-training. Today I have the chance to talk to Maxime Labonne, who's a researcher at Liquid AI and the architect of some of the most popular open source models on Hugging Face. He went from researching neural networks for cybersecurity to building "Frankenstein models" through techniques that shouldn't work but consistently do. Key Insight: Model Merging as a Free LunchThe core breakthrough is deceptively simple: take two fine-tuned models, average their weights layer by layer, and often get better performance than either individual model. Maxime initially started writing an article to explain why this couldn't work, but his own experiments convinced him otherwise. The magic lies in knowledge compression and regularization. When you train a model multiple times on similar data, each run creates slightly different weight configurations due to training noise. Averaging these weights creates a smoother optimization path that avoids local minima. You can literally run model merging on a CPU - no GPUs required. In the podcast, we also touch on: Obliteration: removing safety refusal mechanisms without retraining Why synthetic data now comprises 90%+ of fine-tuning datasets The evaluation crisis and automated benchmarks missing real-world performance Chain of thought compression techniques for reasoning models 💡 Core Concepts Model Merging: Averaging weights across layers from multiple fine-tuned models to create improved performance without additional training Obliteration: Training-free method to remove refusal directions from models by computing activation differences Linear Merging: The least opinionated merging technique that simply averages weights with optional scaling factors Refusal Direction: The activation pattern that indicates when a model will output a safety refusal 📶 Connect with Maxime: X / Twitter: https://x.com/maximelabonne LinkedIn: https://www.linkedin.com/in/maxime-labonne/ Company: https://www.liquid.ai/ 📶 Connect with Nicolay: LinkedIn: https://www.linkedin.com/in/nicolay-gerold/ X / Twitter: https://x.com/nicolaygerold Website: https://www.nicolaygerold.com/ ⏱ Important Moments Model Merging Discovery Process: [00:00:30] Maxime explains how he started writing an article to debunk model merging Two Main Merging Use Cases: [11:04] Clear distinction between merging checkpoints versus combining different task-specific capabilities Linear Merging as Best Practice: [21:00] Why simple weight averaging consistently outperforms more complex techniques Layer Importance Hierarchy: [21:18] First and last layers have the most influence on model behavior Obliteration Technique Explained: [36:07] How to compute and subtract refusal directions from model activations Synthetic Data Dominance: [50:00] Modern fine-tuning uses 90%+ synthetic data 🛠 Tools & Tech Mentioned MergeKit: https://github.com/cg123/mergekit Transformer Lens: https://github.com/TransformerLensOrg/TransformerLens Hugging Face Transformers: https://github.com/huggingface/transformers PyTorch: https://pytorch.org/ 📚 Recommended Resources Maxime's Model Merging Articles: https://huggingface.co/blog/merge Model Soups Paper: https://arxiv.org/abs/2203.05482 Will Brown's Rubric Engineering: https://x.com/willccbb/status/1883611121577517092

Jul 23, 2025

Nicolay here, Most AI coding tools obsess over automating everything. This conversation focuses on the right balance between human skill and AI assistance - where manual context beats web search every time. Today I have the chance to talk to Ben Holmes, a software engineer at Warp, where they're building the AI-first terminal. Manual context engineering trumps automated web search for getting accurate results from coding assistants. Key Insight Expansion The breakthrough insight is brutally practical: manual context construction consistently outperforms automated web search when working with AI coding assistants. Instead of letting your AI tool search for documentation, find the right pages yourself and feed them directly into the model's context window. Ben demonstrated this with OpenAI's Realtime API documentation - after an hour of back-and-forth with web search, he manually found the correct API signatures and saved them as a reference file. When building new features, he attached this curated documentation directly, resulting in immediate success rather than repeated failures from outdated or incorrect search results. This approach works because you can verify documentation accuracy before feeding it to the AI, while web search often returns the first result regardless of quality or recency. In the podcast, we also touch on: Why React Native might become irrelevant as AI translation between native languages improves Model-specific strengths: Gemini excels at debugging while Claude dominates f unction calling The skill of working without AI assistance - "raw dogging" code for deep learning Warp's architecture using different models for planning (O1/O3) vs. coding (Claude/Gemini) 💡 Core Concepts Manual Context Engineering: Curating documentation, diagrams, and reference materials directly rather than relying on automated web search. Model-Specific Workflows: Matching AI models to their strengths - O1 for planning, Claude for f unction calling, Gemini for debugging. Raw Dog Programming: Coding without AI assistance to build f undamental skills in codebase navigation and problem-solving. Agent Mode Architecture: Multi-model system where Claude orchestrates task distribution to specialized agents through f unction calls. 📶 Connect with Ben: Twitter/X, YouTube, Discord (Warp Community), Website 📶 Connect with Nicolay: LinkedIn, X/Twitter, Bluesky, Website, [email protected] ⏱ Important Moments React Native's Potential O bsolescence: [08:42] AI translation between native languages could eliminate cross-platform frameworks Manual vs Automated Context: [51:42] Why manually curating documentation beats AI web search Raw Dog Programming Benefits: [12:00] Value of coding without AI assistance during Ben's first week at Warp Model-Specific Strengths: [26:00] Gemini's superior debugging vs Claude's speculative code fixes OpenAI Desktop App Advantage: [13:44] O utperforms Cursor for reading long files Warp's Multi-Model Architecture: [31:00] How Warp uses O1/O3 for planning, Claude for orchestration Function Calling Accuracy: [28:30] Claude outperforms other models at chaining f unction calls AI as Improv Partner: [56:06] Current AI says "yes and" to everything rather than pushing back 🛠 Tools & Tech Mentioned Warp Terminal, OpenAI Desktop App, Cursor, Cline, Go by Example, OpenAI Realtime API, MCP 📚 Recommended Resources Warp Discord Community, Ben's YouTube Channel, Go Programming Documentation 🔮 What's Next Next week, we continue exploring production AI implementations with more insights into getting generative AI systems deployed effectively. 💬 Join The Conversation Follow How AI Is Built on YouTube, Bluesky, or Spotify. Discord coming soon! ♻ Building the platform for engineers to share production experience. Pay it forward by sharing with one engineer facing similar challenges. ♻

See all episodes →