Member-only story

🛒 AI-Powered Grocery Search: Building a Neo4j Graph App with Streamlit & Magic! ✨

Aditya Mangal
5 min readMar 13, 2025

--

🚀 Introduction

So, you’ve got a ton of product data, and you want to search it semantically — like a human, not a robot that only understands exact matches. But traditional databases don’t cut it, and vector databases sound too complicated. Enter Neo4j, the graph database that makes relationships as easy to handle as your Netflix recommendations.

In this blog, we’ll go from zero to hero, setting up Neo4j, uploading product data, and integrating it into a Streamlit-powered AI app for natural language search. And yes, we’re throwing in some LLM magic! ✨

🏗️ Step 1: Setting Up Neo4j & Uploading Data

1. Install Dependencies

Before diving in, install the necessary Python libraries:

pip install pandas neo4j streamlit langchain langchain-community langchain-groq

2. Connect to Neo4j & Upload Data

We’re using Neo4j Aura (a cloud-based instance) for simplicity. Here’s how we insert our product data:
Download the data -> Kaggle

import pandas as pd
from neo4j import GraphDatabase
# Load CSV dataset
file_path = "BigBasket_Products.csv"
df = pd.read_csv(file_path)
# Neo4j Connection Details
uri = "neo4j+s://your-database-url"
username = "neo4j"
password = "your-password"
# Create Neo4j Driver
driver = GraphDatabase.driver(uri, auth=(username, password))
# Cypher Query for Insertion
def insert_product(tx, product, sale_price, market_price, p_type, rating, brand, category, sub_category):
if pd.isna(product) or pd.isna(brand) or pd.isna(category) or pd.isna(sub_category):
return # Skip rows with essential missing values
query = """
MERGE (p:Product {name: $product})
SET p.sale_price = $sale_price,
p.market_price = $market_price,
p.type = $p_type,
p.rating = $rating
MERGE (b:Brand {name: $brand})
MERGE (c:Category {name: $category})
MERGE (sc:SubCategory {name: $sub_category})
MERGE (p)-[:BELONGS_TO]->(b)
MERGE (p)-[:IN_CATEGORY]->(c)
MERGE (p)-[:IN_SUBCATEGORY]->(sc)
"""
tx.run(query, product=product…

--

--

Aditya Mangal
Aditya Mangal

Written by Aditya Mangal

My Personal Quote to overcome problems and remove dependencies - "It's not the car, it's the driver who win the race".

No responses yet