← back

Building efficient hybrid context query for LLM grounding: Simrat Hanspal

274 views · Feb 05, 2025 · 11:34 min · Watch on YouTube ↗
Takeaway

Use a permissions-aware GraphQL data layer like Hasura to make RAG retrieval hybrid (semantic + structured) and to lock down LLM-generated query injection.

Summary

  • Hanspal (Hasura DevRel) demos building a RAG product-search pipeline over both vector and relational data using a single Hasura GraphQL API.
  • Three query types unified: semantic ('essential oils for relaxation' → vector search), structured ('products under $500' → SQL filter), and hybrid ('essential-oil diffusers between $500–$1000').
  • Demonstrates a prompt-injection attack where an LLM-generated GraphQL insert mutation actually creates a fake product row — then fixes it by defining a restricted Hasura role with select-only permissions.
  • Argues data-driven apps used to have constant data and changing queries; RAG inverts that — natural-language queries make role-based, schema-aware authorization the new security frontier.
raghasuragraphql
Original description
Natural language queries have opened new doors for improving customer experiences. But not all queries can be issued directly on LLMs. Many require supporting context for LLM grounding.
Fetching relevant context can range from simple to complex. Let us understand this with an example of e-commerce. 

1. Simple - Semantically similar text from vector db 
Ex: vibrant red with glitter and versatile for travel
2. Slightly complex - Semantically similar text from vector db, which belongs to an entity 
Ex: vibrant red shoes with glitter and versatile for travel
3. Highly complex - Semantically similar text from vector db, which belongs to an entity with structured filters
(vibrant red shoes with glitter and versatile for travel within the price range of $500-1000)

Handling such queries would require mapping of vector data to existing data models. Highly complex queries would also require issuing multiple queries to relational and vector db. Finally, the results would be put together with intersection operation.
This small engineering effort explodes into the project of its own very soon with more data sources. What a mess! 

In this talk, I will be explaining how Hasura's GraphQL API provides an efficient solution to multi-source queries for GenAI applications.

Recorded & streamed live for the AI Engineer Summit 2023. See the full schedule of talks at https://ai.engineer/summit/schedule & join us at the AI Engineer World's Fair in 2024! Get your tickets today at https://ai.engineer/worlds-fair

About Simrat
Data Scientist with a curious engineering mind. Currently working as Technical Evangelist at Hasura. Helping the community build better data products with Hasura.
Prior to Hasura, worked for 12+ years as an Applied Data scientist building intelligent products and solutions ground up.