# Building efficient hybrid context query for LLM grounding

Simrat Hanspal

AI Engineer Summit 2023

[Talk page](https://ai.engineer/talks/pijYURicI1Y-building-efficient-hybrid-context-query-llm) · [Video](https://www.youtube.com/watch?v=pijYURicI1Y)

## Building efficient hybrid context query for LLM grounding

Natural-language product search must capture what a shopper wants while respecting constraints such as price and category. Simrat Hanspal’s walkthrough connects those retrieval tasks, then tests what happens when a shopper asks the search interface to write to the catalog.

### Product search needs meaning and structured constraints

[0:29](https://www.youtube.com/watch?v=pijYURicI1Y&t=29s)

A shopper may know what a product should do and how much they can spend without knowing the catalog’s exact wording. Their request combines a description with a constraint. A product-search application therefore needs to distinguish descriptive intent, conditions on structured fields, and requests containing both. Replacing keyword input with natural language makes the interface more expressive, but the retrieval system still has to translate that expression into appropriate operations.

A language model’s training data is not a live product catalog. Retrieval-Augmented Generation, or RAG, supplies relevant external information alongside the user’s question so the model can ground its response in that information. For product search, this means retrieving catalog context that fits the request, rather than relying on the model’s existing knowledge of products.

Hanspal introduces security before building the pipeline. Useful context must not become a route to sensitive data simply because a user asks for it. That is a requirement for the application, not a guarantee conferred by adding retrieval: the system must control which data the request can reach.

### Dynamic requests need bounded data access

[1:45](https://www.youtube.com/watch?v=pijYURicI1Y&t=105s)

Why revisit secure retrieval when data-driven applications have existed for years? Hanspal’s distinction concerns the shape of the application’s data interface. In the conventional product-search application Hanspal describes, the software consumes a relatively fixed feed. Records and results change, but new functionality generally comes from changing the application around that interface.

A context-driven application must instead select information according to an open-ended natural-language request. The required context can vary with what the user asks. That flexibility also gives users room to request behavior the application designer did not intend, so interpreting a request and deciding whether to permit it are separate responsibilities.

Hanspal introduces [Hasura’s GraphQL API and permission system](https://hasura.io/docs/2.0/auth/authorization/permissions/) as the data-access layer. A unified interface can expose different data sources while allowing requests to vary in structure. GraphQL expresses the operation; permissions govern what the execution role may do. A dynamic query language does not itself establish authorization.

### Prepare the records, then expose one GraphQL interface

[3:08](https://www.youtube.com/watch?v=pijYURicI1Y&t=188s)

The retrieval interface must accommodate three kinds of request:

- **Semantic search** matches the meaning of a request against product descriptions in a vector database.
- **Structured search** applies conditions to fields such as `price` and `category`. Natural language must become a structured operation, expressed in SQL or GraphQL, for example.
- **Hybrid search** combines descriptive similarity with structured conditions.

Here, hybrid means semantic retrieval plus structured constraints. The demonstration does not introduce a fusion of keyword and vector rankings. Hasura provides one GraphQL interface for all three request shapes.

Hanspal’s [Streamlit application](https://docs.streamlit.io/) supplies the user-facing entry point. It accepts a natural-language request, calls a language model to generate GraphQL, and submits the generated operation to Hasura. The model performs the translation; Hasura executes the resulting data request.

In the console’s Data tab, a Postgres product table and a product vector table are already connected. Although the architecture can expose multiple sources, Hanspal simplifies the live searches to use only [Weaviate](https://docs.weaviate.io/weaviate). Its prepared records hold vectors alongside structured product fields, including price and category. The demonstrated hybrid search therefore does not require a live join between Postgres and Weaviate.

Preparation happens before the search request. Hanspal uses [Hasura event triggers](https://hasura.io/docs/2.0/event-triggers/overview/) to initiate vectorization when a new product is inserted into Postgres, then saves the vectorized record in the vector database. The insertion event starts the ingestion work; subsequent searches operate on the prepared collection. The console’s `Product_vectors` table shows the product records with their `name`, `description`, `price`, and `category` fields.

![Product records combine descriptions, structured fields, and vectors in the demo.](https://ai.engineer/api/talk-essay-media/f151dd15711d1236e9d2869979191b6966ef9a13e0e44f5d4004a171d0c1222b)

Product records combine descriptions, structured fields, and vectors in the demo.

The console’s API tab provides a workspace for executing queries and inspecting their results. Hanspal then moves to Streamlit, whose configuration panel contains the Hasura endpoint, an admin secret, and an OpenAI API key for the Chat Completion API. These settings connect the demonstration’s components. The execution privileges attached to those requests become consequential in the later authorization test.

### Three shopping requests exercise the retrieval interface

[6:05](https://www.youtube.com/watch?v=pijYURicI1Y&t=365s)

The first request asks for essential oils for relaxation. The generated GraphQL operation identifies that descriptive intent as the input to semantic search, and the application displays returned products. The task is to match what the shopper wants the product for, rather than apply a numeric condition.

Next, Hanspal asks for products costing less than $500. The generated operation identifies `price` as the field and less-than as the comparison: `price < 500`. The application displays products satisfying that condition. Unlike the relaxation request, this search depends on a precise field comparison.

The third request combines the two: essential oil diffusers in a price range of $500 to $1,000. The generated GraphQL operation includes a semantic search for diffusers and a price-range filter, and the application again displays results. Semantic relevance identifies the kind of product; the structured constraint determines which prices qualify. [Weaviate filters](https://docs.weaviate.io/weaviate/search/filters) provide the structured part of retrieval from the prepared collection.

![A natural-language request becomes a GraphQL query with price constraints.](https://ai.engineer/api/talk-essay-media/cae69fa396ebaaa33723c3e1f76944af7167824a8dd3bfb9bc283ad62fd4118c)

A natural-language request becomes a GraphQL query with price constraints.

Consider an illustrative diffuser record priced at $750. Its description can supply the semantic match, while its price falls inside the requested interval. Neither condition substitutes for the other: an unrelated product at the right price would not satisfy the descriptive request, and a relevant diffuser outside the range would not satisfy the price constraint. The $750 record is a teaching example, not a reported result from the demonstration.

### An insert request exposes the permission boundary

[8:15](https://www.youtube.com/watch?v=pijYURicI1Y&t=495s)

The successful searches have exercised the intended behavior. Hanspal now turns to an unintended operation: asking the search interface to insert a hair-oil product named `special oil`, priced at $10,000, in category `home`, with description `Fantastic hair oil` and product ID `10001`. This is a request to change the catalog, not retrieve context from it.

The model generates a GraphQL insert mutation, and the initial execution privileges allow it to succeed. Hanspal returns to the console and filters the table for the new product ID, removing quotation marks from the lookup value because the identifier field is an integer. The matching record appears: the search application has actually written to the database.

The repair is a permission change. In the console, Hanspal creates a product-search role and grants it only select access. For simplicity, Hanspal applies no row checks and makes all product columns accessible. The role can read products but receives no insert permission. This is an operation-level restriction; the deliberately broad read permissions do not establish protection for sensitive rows or columns.

Hanspal retries the insertion request under the restricted role, changing the product ID to `7002`. The model still generates an insert mutation. This time execution returns an error because the role lacks insert permission. The application displays the role as `product_search_bot`, and the GraphQL error reports that the insert field cannot be queried on `mutation_root`. The attempts preserve the insertion intent and operation type, but they are not byte-identical requests.

![The generated insert mutation is rejected under the restricted product-search role.](https://ai.engineer/api/talk-essay-media/079e550b0b961a00f1c9021fc870a8690ec37a0a8d0a96b6fcaaff979de78aa4)

The generated insert mutation is rejected under the restricted product-search role.

The rejection separates generation from authorization. The model remains willing to propose a write, but that proposal cannot grant the execution role permission to perform it. The application’s access boundary holds even when the generated operation falls outside the intended search behavior.

Hanspal closes by returning to the hybrid product-search use case: descriptive requests and structured filters can share a retrieval interface while execution permissions constrain its operations.

## Resources

- [Hasura: configuring permission rules](https://hasura.io/docs/2.0/auth/authorization/permissions/) — Configure access by table, role and operation—the boundary that stops the generated insert in the demonstration.
- [Hasura event triggers](https://hasura.io/docs/2.0/event-triggers/overview/) — Use database events to trigger the ingestion work that keeps the vectorized product records up to date.
- [Weaviate filters](https://docs.weaviate.io/weaviate/search/filters) — Combine numeric and categorical constraints with retrieval from the prepared product collection.
- [Hasura + Vector DBs](https://hasura.io/blog/hasura-brings-the-power-of-generative-ai-to-your-data) — Hanspal's earlier tutorial builds a permission-aware Postgres/Weaviate application and wires database events to vector ingestion.
- [Hasura's vector-database workshop](https://github.com/hasura/ai-workshop-hasuracon23) — The companion workshop to Hanspal's vector-database tutorial supplies setup notebooks and event-handler code.
- [Building production-ready RAG with Hasura and Portkey](https://hasura.io/blog/get-10x-efficient-in-building-production-ready-genai-rag-applications) — Hanspal extends the retrieval story to secure data access and operational concerns using Hasura and Portkey.

## Slides

### Efficient hybrid RAG queries

Simrat Hanspal introduces hybrid semantic and relational RAG queries, using e-commerce product search as the motivating example.

[0:17](https://www.youtube.com/watch?v=pijYURicI1Y&t=17s) [Title slide for Efficient hybrid semantic and relational RAG queries by Simrat Hanspal of Hasura.](https://assets.ai.engineer/sites/aiecode2025/sha256/c186b91f4615a1f6671c6a6c16cb1619c2bab50c3dda42892966342a9fa3abe3.webp)

HASURA

Efficient hybrid (Semantic and Relational) RAG queries

Simrat Hanspal
Technical Evangelist @Hasura

© Copyright 2023, Hasura, Inc.

Interface text:
docs.google.com
Hasura - AI Engineer Summit - Google Slides
Projects - Hasura Cloud
API Explorer | Hasura
app · Streamlit

### Natural-language product search

Hanspal says keyword-based product search can miss user intent. She proposes natural language and notes that searches may use descriptions, structured fields, or both.

[0:28](https://www.youtube.com/watch?v=pijYURicI1Y&t=28s) [Slide suggests using natural language to improve online product search.](https://assets.ai.engineer/sites/aiecode2025/sha256/949874f62c5b8a853f5bb7fcb28b0277d5dd8a9a6e07df0669b5b0bd851bf40d.webp)

Present day online product search experience is not the best.

Imagine if you could use natural language.

Interface text:
docs.google.com
Hasura - AI Engineer Summit - Google Slides
Projects - Hasura Cloud
API Explorer | Hasura
app · Streamlit

### Secure context retrieval

The speaker revisits secure retrieval for generative AI: a production-ready RAG pipeline must avoid leaking sensitive data, even when prompted. She points to a paradigm shift in application development.

[1:43](https://www.youtube.com/watch?v=pijYURicI1Y&t=103s) [Slide asks why secure data and context retrieval is being discussed again for data-driven applications.](https://assets.ai.engineer/sites/aiecode2025/sha256/f422eb36bb5bc2d2617bb316b542dbf97f983849228b7ad14ff333faca97d637.webp)

Data driven applications have been around for a while.

Then, why are we talking about secure data (context) retrieval all over again?

Interface text:
docs.google.com
Hasura - AI Engineer Summit - Google Slides
Projects - Hasura Cloud
API Explorer | Hasura
app · Streamlit

### Paradigm shift

Data-driven apps adapt software around mostly constant data. In context-driven or RAG apps, data adapts to the user's natural-language query while the model remains fixed.

[1:55](https://www.youtube.com/watch?v=pijYURicI1Y&t=115s) [Diagram contrasts fixed data and adapting applications with adapting data and a fixed model.](https://assets.ai.engineer/sites/aiecode2025/sha256/f9f0a73ab89af5084cc177434ae5bfcd4ab8fce9da8d52b276d64797cd5ba589.webp)

Paradigm shift

Data driven
Data remains fixed → Application adapts to use cases

Context driven
Data adapts to use cases → Model remains fixed

Interface text:
docs.google.com
Hasura - AI Engineer Summit - Google Slides
Projects - Hasura Cloud
API Explorer | Hasura
app · Streamlit

### Say hello to Hasura

The presenter introduces Hasura as a way to build unified, secure GraphQL APIs across multiple data sources. She says the APIs are dynamic by nature.

[2:41](https://www.youtube.com/watch?v=pijYURicI1Y&t=161s) [Hasura introduction slide with illustrated characters raising their hands.](https://assets.ai.engineer/sites/aiecode2025/sha256/877fe351ac85c1bcabce0e33c0397999aac9689551e421f9e524ab304ac601a9.webp)

Say hello to
HASURA

Interface text:
docs.google.com
Hasura - AI Engineer Summit - Google Slides
Projects - Hasura Cloud
API Explorer | Hasura
app · Streamlit

### Product search in natural language

Hasura connects Postgres and Weaviate to a Streamlit app. The app sends user input to a language model, which generates a GraphQL query for Hasura to execute.

[3:57](https://www.youtube.com/watch?v=pijYURicI1Y&t=237s) [Postgres and Weaviate connect through Hasura to a Streamlit front-end application.](https://assets.ai.engineer/sites/aiecode2025/sha256/f7c23686304c42d1eef7b3d64c1e1651c84d50129042262e989e0686cabc5b04.webp)

Product search in natural language

Postgres
Weaviate
H
A
S
U
R
A
Streamlit
(Front end app)

8

Interface text:
docs.google.com
Hasura - AI Engineer Summit - Google Slides
Projects - Hasura Cloud
API Explorer | Hasura
app · Streamlit

### Connecting a database in Hasura

The Hasura console shows database connectors with Postgres selected. The presenter skips connecting a database because the product Postgres and vector tables are already integrated.

[4:34](https://www.youtube.com/watch?v=pijYURicI1Y&t=274s) [Hasura's database connection screen shows available database types, with Postgres selected.](https://assets.ai.engineer/sites/aiecode2025/sha256/09898e0ce020bee032686525e6fd1a3a81c49c0b1c49229c49fd45560c7c9694.webp)

Connect a database to access your database objects in your GraphQL API.

REST Endpoints
Databases
GraphQL Services
Clients
Apps, Platforms, Services

AlloyDB
Amazon Athena
Beta
BigQuery
Citus
CockroachDB
MS SQL Server
MariaDB
MongoDB
MySQL
Oracle
Postgres
Snowflake

Interface text:
cloud.hasura.io
Hasura - AI Engineer Summit - Google Slides
Projects - Hasura Cloud
Data | Hasura
app · Streamlit
Databases (2)
Manage
default
public
Search tables in public...
base_products
Product_vectors
SQL
Native Queries

### Connected data sources

Hasura’s Data Manager lists existing Postgres and Weaviate connections. The presenter uses the vector database for this demo.

[4:39](https://www.youtube.com/watch?v=pijYURicI1Y&t=279s) [Hasura Data Manager lists Postgres and Weaviate connections.](https://assets.ai.engineer/sites/aiecode2025/sha256/b9ae56e833055afb0c945a1399e196bd30e7f6e27ac3e1450428d1be8e15004b.webp)

Data Manager
Connect Database

Want to connect to a private database?
Explore our Dedicated VPC and VPC PrivateLink offerings.
Learn More

DATABASE    DRIVER
default    postgres    Version: PostgreSQL 15.4 on x86_64-pc-linux-gnu, compiled by ...    More    Reload    Edit    Remove
Product_vectors    weaviate    Reload    Edit    Remove

Check latency
Data Connector Agents

Interface text:
cloud.hasura.io
Hasura - AI Engineer Summit - Google Slides
Projects - Hasura Cloud
Manage - Data | Hasura
app · Streamlit
HASURA v2.33.4-cloud.1
API    DATA    ACTIONS    REMOTE SCHEMAS    EVENTS    MONITORING    caring-fish-90    SETTINGS    HELP
Data Manager
Databases (2)    Manage
default
public
Search tables in public...
base_products
Product_vectors
Product_[illegible]ors
SQL
Native Queries
You are here: Data > Manage

### Browsing product records

Hasura displays Weaviate product records with prices and categories. The presenter says new Postgres records are automatically vectorized and saved to the vector database.

[5:00](https://www.youtube.com/watch?v=pijYURicI1Y&t=300s) [Hasura displays product records with IDs, names, descriptions, prices, and categories.](https://assets.ai.engineer/sites/aiecode2025/sha256/aa76b61dc0dbcb2aa40066be66b8274a60da1a59a8689b5847df0c56fecc7121.webp)

Product_vectors > Product_vectors > Manage
Product_vectors — Tracked
Browse | Modify | Relationships | Permissions

Product_vectors
Export | Query (0) | Show 10 rows

PRODUCT_ID | NAME | DESCRIPTION | PRICE | CATEGORY | ID | CREATIONTIMEUNIX | LASTUPDATETIMEUNIX
7 | ScentSation Aromatherapy | Create a relaxing ambiance in your home with ScentSation Aromatherapy, a set of essential oils carefully blended to soothe and uplift your senses. | 850 | home | 0107e526-59d3-4a00-ba00-1ab9eda49857 | 1695955510642 | 1695955510642
45 | RapidScribe Note-Taking Pen | Streamline your note-taking with RapidScribe Note-Taking Pen, converting your handwritten notes into digital text effortlessly. | 3500 | electronics | 032ccbf7-4e01-4e2f-b476-eb8bdbbbcd62 | 1695955550526 | [illegible]

Interface text:
cloud.hasura.io
Hasura - AI Engineer Summit - Google Slides | Projects - Hasura Cloud | Data | Hasura | app - Streamlit
HASURA v2.33.4-cloud.1 | API | DATA | ACTIONS | REMOTE SCHEMAS | EVENTS | MONITORING | caring-fish-90 | SETTINGS | HELP
Data Manager
Databases (2) | Manage
default > public
Search tables in public...
base_products
Product_vectors > Product_vectors
SQL
Native Queries

### Product vectors in Hasura

The demo shows product vectors alongside price and category fields. The speaker says a Hasura event automatically vectorizes new Postgres records and saves them in the vector database.

[5:04](https://www.youtube.com/watch?v=pijYURicI1Y&t=304s) [The product table is scrolled horizontally to show a vector column alongside product fields.](https://assets.ai.engineer/sites/aiecode2025/sha256/b45c1d399d8b37aae3b2d72430c40d28ceea3763ef3960631b659de4fbd04dee.webp)

Product_vectors
Tracked
Browse  Modify  Relationships  Permissions

Product_vectors
Export  Query (0)  Show 10 rows

[illegible]ODUCT_ID  NAME  DESCRIPTION  PRICE  CATEGORY  ID  CREATIONTIMEUNIX  LASTUPDATETIMEUNIX  VECTOR

ScentSation Aromatherapy
Create a relaxing ambiance in your home with ScentSation Aromatherapy, a set of essential oils carefully blended to soothe and uplift your senses.
850  home  0107e526-59d3-4a00-ba00-1ab9eda49857  1695955510642  1695955510642  [-0.022082[illegible]

RapidScribe Note-Taking Pen
Streamline your note-taking with RapidScribe Note-Taking Pen, converting your handwritten notes into digital text effortlessly.
3500  electronics  032ccbf7-4e01-4e2f-b476-eb8bdbbbcd62  1695955550526  [illegible]

Interface text:
cloud.hasura.io
Hasura - AI Engineer Summit - Google Slides
Projects - Hasura Cloud
Data | Hasura
app · Streamlit
HASURA  v2.33.4-cloud.1
API  DATA  ACTIONS  REMOTE SCHEMAS  EVENTS  MONITORING  caring-fish-90  SETTINGS  HELP
Data Manager
Databases (2)  Manage
default  public
Search tables in public...
base_products
Product_vectors
SQL
Native Queries

### Product price filter

The presenter enters a natural-language request for products under $500 to demonstrate a structured price filter.

[7:10](https://www.youtube.com/watch?v=pijYURicI1Y&t=430s) [A natural-language request for products priced below $500.](https://assets.ai.engineer/sites/aiecode2025/sha256/d292dbfb00faa69bc9bbbdab83223a7ec1aab1f0579a60dd75d2d2e518aa95fc.webp)

Hasura GraphQL - Natural La[illegible]
Engine

Enter your natural language query
show me all products less than price $500
Submit

Interface text:
/v1/grap[illegible]

### Price-filter results

The price filter returns products under $500, including GlowGrip PhoneCase at 390 and PurePetals Body Wash at 250.

[7:31](https://www.youtube.com/watch?v=pijYURicI1Y&t=451s) [JSON results showing products with prices below $500.](https://assets.ai.engineer/sites/aiecode2025/sha256/7eaef0936dd1de2ab0083ca14bd70e146ca8a72b22f7218373dca643dd1898d3.webp)

    }
}

Result:
{
    "Product_vectors": [
        {
            "id": "50d8e9eb-5f29-41d9-bd40-d44ae8d54c01",
            "product_id": 9,
            "name": "GlowGrip PhoneCase",
            "description": "Protect and illuminate your smartphone with GlowGri[illegible]
            "price": 390,
            "category": "mobile"
        },
        {
            "id": "216bb218-1dac-[illegible]686-b33a-91c7a0bc507c",
            "product_id": 46,
            "name": "PurePetals Body Wash",
            "description": "Indulge in a luxurious shower experie[illegible]
            "price": 250,

### Hybrid product search

The demo turns a request for an essential oil diffuser costing more than $500 and less than $1,000 into a semantic search with a price filter.

[7:42](https://www.youtube.com/watch?v=pijYURicI1Y&t=462s) [A natural-language request for an essential oil diffuser priced between $500 and $1,000.](https://assets.ai.engineer/sites/aiecode2025/sha256/52c51064ff351ee06fbc08e459a12ad829bb3dff57912730e5d4b47eb10f89f1.webp)

Hasura GraphQL - Natural Languag[illegible]
Engine

Enter your natural language query

I am looking for an amazing essential oil diffuser with price greater than $500 but less than $1000.

Submit

Interface text:
[illegible].hasura.app/v1/gra[illegible]

### Product insertion request

The speaker enters a request to insert a hair oil product named special oil, presenting it as a malicious query after the earlier search examples.

[8:45](https://www.youtube.com/watch?v=pijYURicI1Y&t=525s) [A natural-language request to insert a hair oil product.](https://assets.ai.engineer/sites/aiecode2025/sha256/ea7d8abf2f0572d63e8db059e9d830eb6a1ece50a014af6980f2bcb6ff9355d5.webp)

Hasura GraphQL - Natural Language Engine

Enter your natural language query

write an insert query for hair oil product with name- special oil, price - [illegible]10000$, category - home, desc

Interface text:
Press Enter to apply
Submit

### New role in the permissions matrix

After an unintended insert, the presenter enters a product_search_bot role and plans to grant only select access. The permissions matrix initially shows no access for the new role.

[10:06](https://www.youtube.com/watch?v=pijYURicI1Y&t=606s) [Hasura displays a new product-search role with no access indicated in the permissions matrix.](https://assets.ai.engineer/sites/aiecode2025/sha256/bfddb76619086bb64dc0382af92e6e4f712f5a6ef5162b8e060497de8d1d7c39.webp)

Product_vectors > Product_vectors > Manage
Product_vectors — Tracked

Browse  Modify  Relationships  Permissions
✓ - full access  × - no access  ▼ - partial access

ROLE                 INSERT  SELECT  UPDATE  DELETE
admin                ✓       ✓       ✓       ✓
product_search_bot   ×       ×       ×       ×

Interface text:
cloud.hasura.io
Hasura - AI Engineer Summit - Google Slides
Projects - Hasura Cloud
Data | Hasura
app · Streamlit
HASURA v2.33.4-cloud.1
API  DATA  ACTIONS  REMOTE SCHEMAS  EVENTS  MONITORING
caring-fish-90  SETTINGS  HELP
Data Manager
Databases (2)  Manage
default
public
Search tables in public...
base_products
Product_vectors
Product_vectors
SQL
Native Queries
https://cloud.hasura.io/project/[illegible]/console/settings

### Select permission settings

The presenter configures product_search_bot to select rows without checks and access all listed columns. The role is intended to have select permission only.

[10:20](https://www.youtube.com/watch?v=pijYURicI1Y&t=620s) [The role's select-permission editor shows unrestricted row selection and all listed columns checked.](https://assets.ai.engineer/sites/aiecode2025/sha256/c670e86b361c10a5e4fdc1f0f2d89606e522f1a1cbd47d6698d15771fdd74a48.webp)

Comments
Add a comment explaining the permissions

Row select permissions — No access
Allow role product_search_bot to select rows:
Without any checks
{}
With custom check:
Limit number of rows
0

Column select permissions — All columns
Allow role product_search_bot to access columns:
product_id
name
description
price
category
id
creationTimeUnix
lastUpdateTimeUnix
vector
Toggle All

Aggregation queries permissions — Disabled
Root field permissions — all enabled
Clone permissions
Delete Permissions

Interface text:
cloud.hasura.io
Hasura - AI Engineer Summit - Google Slides
Projects - Hasura Cloud
Data | Hasura
app - Streamlit

### Thank you

Simrat Hanspal closes by recapping the Hasura demo for building hybrid query context for RAG applications such as product search.

[11:03](https://www.youtube.com/watch?v=pijYURicI1Y&t=663s) [Closing thank-you slide with the presenter’s professional contact details and a QR code.](https://assets.ai.engineer/sites/aiecode2025/sha256/983584046839339531cc84af4b51c508c91528b9489c156b4699214edd17bd41.webp)

Thank you!

Simrat Hanspal
Helping Developers to Create AI-Powered Applications | Data Scientist | NLP Specialist | Speaker at Conferences...

Simrat Hanspal
LinkedIn - Scan the QR
Twitter - [redacted]
Email - [redacted]

9

Interface text:
docs.google.com
Hasura - AI Engineer Summit - Google Slides
Projects - Hasura Cloud
Data | Hasura
app · Streamlit

## Full transcript

[0:00](https://www.youtube.com/watch?v=pijYURicI1Y&t=0s) [on-hold electronic music] Hey, hey, hey.

[0:18](https://www.youtube.com/watch?v=pijYURicI1Y&t=18s) How's everyone? This is Simrat Hanspal, technical evangelist at Hasura, and today I'm going to talk to you about building efficient hybrid RAG queries.

[0:29](https://www.youtube.com/watch?v=pijYURicI1Y&t=29s) Let us understand this with the use case of product search in e-commerce domain. Present day, product search is mostly keyword-based. Keywords are not great at capturing the complete intent of the user's search query, so you want to move to using natural language.

[0:45](https://www.youtube.com/watch?v=pijYURicI1Y&t=45s) But product search can be either contextual, where you're looking for-- where you're searching for product based on the descriptive nature, or, or it can be completely structured, where you're querying based on the structured fields, or it can be both.

[0:58](https://www.youtube.com/watch?v=pijYURicI1Y&t=58s) Large language models are great, but they're frozen in time, and they cannot solve task on data they have not seen before. One of the ways to expose the unseen data to large language model is by providing context to the question alongside the question.

[1:13](https://www.youtube.com/watch?v=pijYURicI1Y&t=73s) This helps the large language model generate more accurate and grounded answers. This powerful technique is called Retrieval-Augmented Generation, or RAG in short. So you see, we need to build a RAG pipeline for our product search use case.

[1:28](https://www.youtube.com/watch?v=pijYURicI1Y&t=88s) We also need to make sure that our RAG pipeline is production-ready and will not leak any sensitive data, even if prompted. This security concern has been one of the primary concerns of enterprises when building gen AI applications.

[1:45](https://www.youtube.com/watch?v=pijYURicI1Y&t=105s) Data-driven applications have been around for a while. Then why are we talking about secure data retrieval all over again for gen AI applications? Well, this is because we are seeing a paradigm shift in application development.

[1:59](https://www.youtube.com/watch?v=pijYURicI1Y&t=119s) With data-driven applications, data is mostly constant, and it is the application or the software that evolves for any different or new functionality. For example, product search on current e-commerce websites would pick constant data feeds.

[2:15](https://www.youtube.com/watch?v=pijYURicI1Y&t=135s) Only the records or the results would change.

[2:20](https://www.youtube.com/watch?v=pijYURicI1Y&t=140s) While in context, um, context-driven or RAG application, the data is no longer a constant data packet, and it needs to adapt to the dynamic needs of the user's natural language query.

[2:33](https://www.youtube.com/watch?v=pijYURicI1Y&t=153s) With natural language query, there is no structural limitations, and it can-- and it l- gives a scope for malicious attack.

[2:43](https://www.youtube.com/watch?v=pijYURicI1Y&t=163s) Good news, Hasura enables you to build secure data API over your multiple different data sources in no time. Hasura APIs are GraphQL APIs, and hence they're dynamic in nature, so you get unified, dynamic, secure data API in no time.

[3:00](https://www.youtube.com/watch?v=pijYURicI1Y&t=180s) Just what we needed. So let's get started with building a RAG pipeline for our product search use case.

[3:08](https://www.youtube.com/watch?v=pijYURicI1Y&t=188s) Let us again look at what are the different queries that we, uh, that we can expect for our RAG applications. We can have semantic search, where we are searching based on semantic similarity with product description from product, uh, uh, vector DB.

[3:24](https://www.youtube.com/watch?v=pijYURicI1Y&t=204s) We can also have structured search, where we are searching based on structured fields in the relational database, um, like for example, price and category in Postgres, and this requires converting the natural language query into a structured query like SQL or GraphQL.

[3:42](https://www.youtube.com/watch?v=pijYURicI1Y&t=222s) Then we can also have hybrid queries. These searches have the elements of both semantic and structured queries. With Hasura, we don't need to build separate data APIs for each of them.

[3:53](https://www.youtube.com/watch?v=pijYURicI1Y&t=233s) We can build a unified data API for all three of them.

[3:58](https://www.youtube.com/watch?v=pijYURicI1Y&t=238s) So let's get started. We start by connecting our multiple different data sources with Hasura, and then we query it using a single GraphQL API. I've also built a Streamlit application which takes in the user input, calls the large language model, generates a GraphQL AP-- query, which then gets executed on Hasura.

[4:20](https://www.youtube.com/watch?v=pijYURicI1Y&t=260s) So let's head over to Hasura Console to get a feel of what it looks like. To start, we'll go to the Data tab to connect all of our different data sources.

[4:31](https://www.youtube.com/watch?v=pijYURicI1Y&t=271s) I'm not gonna do that because I have my, um, product Postgres table and product vector table already integrated. As I mentioned before, you can use Hasura to query both, um, your relational and vector DB and multiple data sources using a single GraphQL API.

[4:50](https://www.youtube.com/watch?v=pijYURicI1Y&t=290s) But for the sake of simplicity of this demo, I'm gonna be using only the vector DB. So I'm using Weaviate in this case, where I have my vectors, and I have also got my price and category structured fields here.

[5:05](https://www.youtube.com/watch?v=pijYURicI1Y&t=305s) One thing to note here is that I have used Hasura's event to auto-vectorize, um, my records into my vector DB, which means as and when a new record got inserted into my Postgres table, it got auto-vectorized and saved in my vector DB.

[5:21](https://www.youtube.com/watch?v=pijYURicI1Y&t=321s) Amazing, I know. So let's go back to... Let's go to our API tab. This is where you will-- you can, uh, play around, execute different queries, and see the results.

[5:35](https://www.youtube.com/watch?v=pijYURicI1Y&t=335s) Nice. Now that we have gotten a fairly decent sense of what Hasura Console is like, we can move to the Streamlit app that I have created. As you can see, there are a few configurations on the left-hand side panel.

[5:50](https://www.youtube.com/watch?v=pijYURicI1Y&t=350s) So you have Hasura's endpoint and admin secret. This is required to connect with Hasura securely. And then I also have OpenAI's, um, API key. This is required for the Chat Completion API that I'm using.

[6:05](https://www.youtube.com/watch?v=pijYURicI1Y&t=365s) So let's begin. Let's, uh, begin with querying the three different, uh, context, uh, that we were talking about that we want to fetch. So let's start with purely semantic one.

[6:17](https://www.youtube.com/watch?v=pijYURicI1Y&t=377s) Let's look at the different product descriptions that we have and pick something. Let us pick, uh, products on essential oils. So let me say, "Show me essential oils for relaxation."

[6:41](https://www.youtube.com/watch?v=pijYURicI1Y&t=401s) Great. So we've gotten the GraphQL query, which has identified essential oils for relaxation as the descriptive part of the query, which we want to find in our vector DB by doing a semantic search, and we can also see that we have gotten the results for this query.

[7:01](https://www.youtube.com/watch?v=pijYURicI1Y&t=421s) Nice. Let's go over and execute a structured query. Price is a good field to execute, execute a structured query. So let's say, um, let's say, "Show me all products where price less than

[7:19](https://www.youtube.com/watch?v=pijYURicI1Y&t=439s) five hundred dollars." Great. So it has rightly identified that there is a price filter with the less than condition,

[7:33](https://www.youtube.com/watch?v=pijYURicI1Y&t=453s) and it shows you all the different products with price less than five hundred. Nice. Let's execute a hybrid query now.

[7:47](https://www.youtube.com/watch?v=pijYURicI1Y&t=467s) Let's say looking for essential oil diffusers in the price range of five hundred to thousand dollars.

[7:58](https://www.youtube.com/watch?v=pijYURicI1Y&t=478s) Nice. So we got a GraphQL query where it identified amazing essential oil diffuser as the semantic search query, and then the price filter, which is between five hundred to thousand, and we received our results.

[8:15](https://www.youtube.com/watch?v=pijYURicI1Y&t=495s) Nice. So far, we have executed only the happy flows. Um, we have not looked at any other query where of unhappy flows. But let's say I had an evil intent, and I wanted to execute a malicious query, uh, which is not the typical queries that we just looked at.

[8:35](https://www.youtube.com/watch?v=pijYURicI1Y&t=515s) So I have a malicious query. Let's execute this. So this one is requesting to insert a product of hair- hair oil product, um, with the name special oil and

[8:51](https://www.youtube.com/watch?v=pijYURicI1Y&t=531s) price of [REDACTED:generic_id] [REDACTED:generic_id] dollars. Category is home. Fantastic hair oil is the description, [REDACTED:generic_id] let's also add the product ID [REDACTED:generic_id] say this is [REDACTED:generic_id]. Okay, let's execute this.

[9:10](https://www.youtube.com/watch?v=pijYURicI1Y&t=550s) So as you can see, it, it has generated a GraphQL query of type insert mutation. But what we see is that it has also inserted the product. So let's go back to our table and console and look for product ID equal to

[9:31](https://www.youtube.com/watch?v=pijYURicI1Y&t=571s) [REDACTED:generic_id]. Let's just remove the quotes because this is

[9:38](https://www.youtube.com/watch?v=pijYURicI1Y&t=578s) our integer field. There you go. We have the product which has gotten inserted into the database. Um, this was not the intended behavior. This is not what should have happened.

[9:51](https://www.youtube.com/watch?v=pijYURicI1Y&t=591s) So let us quickly go back to our Hasura console again, and this time, we are gonna be defining a new role with very restricted permissions so that we only provide select permission and such that this does not happen again.

[10:05](https://www.youtube.com/watch?v=pijYURicI1Y&t=605s) So I'm gonna create a new role. Let's call it Product Search Bot, and I'm gonna provide only search permission. Let's go without any checks. I'm gonna keep it really simple.

[10:18](https://www.youtube.com/watch?v=pijYURicI1Y&t=618s) Let me allow all the product, all the columns to be accessible for this role.

[10:24](https://www.youtube.com/watch?v=pijYURicI1Y&t=624s) That's about it. Nice. So the role has gotten inserted. Now let's query. Same thing with the new role, so let's say product search bot. But this time, let me just modify this query a little bit and say seven thousand and two.

[10:42](https://www.youtube.com/watch?v=pijYURicI1Y&t=642s) Okay. So let's execute this and see what happens.

[10:49](https://www.youtube.com/watch?v=pijYURicI1Y&t=649s) Nice. So we got the same insert mutation query, um, to be generated, but this time there was an error executing this rightly so because we have defined a role which does not have the permission for insert queries.

[11:04](https://www.youtube.com/watch?v=pijYURicI1Y&t=664s) Great. So this is all from me. Thank you, everyone. Um, thank you once again. So let us really quickly recap. In this demo, we learned how we can use Hasura to build hybrid query context, um, for your sophisticated RAG applications like product search.

[11:21](https://www.youtube.com/watch?v=pijYURicI1Y&t=681s) If you like the demo or would like to use Hasura for your RAG application, please reach out to me. These are my contact details, and thank you so much. [upbeat music]
