Skip to content

LLM project to connect to an API and find the best restaurants for a certain food craving in a certain city

Notifications You must be signed in to change notification settings

Shameendra/Restaurant_Rag_API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

18 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿฝ๏ธ Restaurant RAG System

A Retrieval-Augmented Generation (RAG) system built with LangChain and LangGraph that helps users find restaurants serving specific dishes in any city. The system scrapes live restaurant data, stores it in a vector database, and uses an LLM to provide intelligent recommendations.

๐ŸŽฏ Features

  • Natural Language Queries: Ask questions like "Where can I find pizza in Frankfurt?"
  • Live Data Scraping: Fetches real-time restaurant data from multiple sources
  • RAG Architecture: Uses vector embeddings for semantic search
  • LangGraph Agent: Sophisticated multi-step reasoning workflow
  • Multiple Data Sources: Supports Yelp API, Google Places (via SerpAPI), and web scraping
  • REST API: FastAPI server for integration with other applications
  • Interactive CLI: Chat-style command line interface

๐Ÿ—๏ธ Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                      User Query                             โ”‚
โ”‚            "Where can I find sushi in Seattle?"             โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                      โ”‚
                      โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                   Query Parser (LLM)                        โ”‚
โ”‚              Extracts: city="Seattle", dish="sushi"         โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                      โ”‚
                      โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                  Web Scraper Module                         โ”‚
โ”‚    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”         โ”‚
โ”‚    โ”‚   Yelp   โ”‚  โ”‚  Google  โ”‚  โ”‚  Generic Scraper โ”‚         โ”‚
โ”‚    โ”‚   API    โ”‚  โ”‚  Places  โ”‚  โ”‚   (Fallback)     โ”‚         โ”‚
โ”‚    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜         โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                      โ”‚
                      โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                   Vector Store (FAISS)                      โ”‚
โ”‚           Embeds restaurant data using OpenAI               โ”‚
โ”‚           Enables semantic similarity search                โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                      โ”‚
                      โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚              LangGraph Agent / RAG Chain                    โ”‚
โ”‚    Retrieves relevant restaurants & generates response      โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                      โ”‚
                      โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
|                    Final Response                           โ”‚
โ”‚    Here are the top 5 sushi restaurants in Seattle:         โ”‚
โ”‚        1.Sushi Kashiba -  4.8 (2,341 reviews)...            โ”‚                                      
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ“ Project Structure

restaurant-rag-project/
โ”œโ”€โ”€ config.py          # Configuration settings and API keys
โ”œโ”€โ”€ scraper.py         # Web scraping modules for restaurant data
โ”œโ”€โ”€ rag_engine.py      # RAG system with vector store
โ”œโ”€โ”€ agent.py           # LangGraph agent implementation
โ”œโ”€โ”€ main.py            # CLI application entry point
โ”œโ”€โ”€ api.py             # FastAPI REST server
โ”œโ”€โ”€ requirements.txt   # Python dependencies
โ”œโ”€โ”€ .env.example       # Environment variables template
โ””โ”€โ”€ README.md          # This file

๐Ÿš€ Quick Start

1. Clone and Setup

# Clone or create the project directory
cd restaurant-rag-project

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

2. Configure API Keys

# Copy the example environment file
cp .env.example .env

# Edit .env and add your API keys
nano .env  # or use your preferred editor

Required:

Optional (for better results):

3. Run the Application

Interactive Mode:

python main.py --interactive

Single Query:

python main.py --query "Where can I find pizza in Frankfurt?"

Structured Search:

python main.py --city "Munich" --dish "sushi"

Start API Server:

python api.py
# API available at http://localhost:8000
# Docs at http://localhost:8000/docs

๐Ÿ’ป Usage Examples

Python API

from main import RestaurantFinder, quick_search

# Using the RestaurantFinder class
finder = RestaurantFinder()
result = finder.find("Where can I find tacos in London?")
print(result)

# Quick search function
result = quick_search("Tokyo", "deep dish pizza")
print(result)

REST API

Query Endpoint:

curl -X POST "http://localhost:8000/query" \
  -H "Content-Type: application/json" \
  -d '{"query": "Best sushi in Seattle", "use_agent": true}'

Search Endpoint:

curl -X POST "http://localhost:8000/search" \
  -H "Content-Type: application/json" \
  -d '{"city": "New York", "dish": "pizza", "top_k": 5}'

Simple GET Request:

curl "http://localhost:8000/ask?q=Where+can+I+find+ramen+in+Tokyo"

LangGraph Agent Direct Usage

from agent import RestaurantAgent

agent = RestaurantAgent()

# Single query
response = agent.query("Where can I find authentic Italian food in Boston?")
print(response)

# Chat with history
from langchain_core.messages import HumanMessage, AIMessage

history = []
response1 = agent.chat("Find pizza places in NYC", history)
history.append(HumanMessage(content="Find pizza places in NYC"))
history.append(AIMessage(content=response1))

response2 = agent.chat("Which one has the best reviews?", history)
print(response2)

๐Ÿ”ง Configuration

Edit config.py to customize:

# LLM Settings
LLM_MODEL = "gpt-4o-mini"  # or "gpt-4o" for better results
TEMPERATURE = 0.3

# Search Settings
TOP_K_RESULTS = 5
MAX_RESTAURANTS_TO_SCRAPE = 20

# Vector Store Settings
CHUNK_SIZE = 500
CHUNK_OVERLAP = 50

๐Ÿ“Š How It Works

1. Query Parsing

The system uses an LLM to extract the city and dish from natural language queries:

  • Input: "Where can I find the best pizza in New York City?"
  • Output: city="New York City", dish="pizza"

2. Data Collection

Multiple scrapers fetch restaurant data:

  • Yelp API: Ratings, reviews, business details
  • Google Places: Location data, popular dishes
  • Generic Scraper: Fallback web scraping

3. Vector Embedding

Restaurant data is converted to text and embedded:

Restaurant: Joe's Pizza
Location: 7 Carmine St, New York
Rating: 4.5/5 (3,241 reviews)
Cuisine: Pizza, Italian
Menu Items: Margherita, Pepperoni, Cheese Slice...

4. Semantic Search

User queries are embedded and matched against restaurant vectors using FAISS for efficient similarity search.

5. Response Generation

The LLM generates a natural language response based on retrieved restaurant data, including:

  • Restaurant names and rankings
  • Ratings and review counts
  • Addresses and contact info
  • Relevant menu items

๐Ÿงช Testing

# Run tests
pytest tests/

# Run with coverage
pytest --cov=. tests/

๐Ÿณ Docker Deployment

# Dockerfile
FROM python:3.11-slim

WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

COPY . .

EXPOSE 8000
CMD ["python", "api.py"]
# Build and run
docker build -t restaurant-rag .
docker run -p 8000:8000 --env-file .env restaurant-rag

๐Ÿ” Security Notes

  • Never commit .env files with real API keys
  • Use environment variables in production
  • Rate limit API endpoints in production
  • Respect website robots.txt when scraping

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Run tests
  5. Submit a pull request

๐Ÿ“ License

MIT License - feel free to use this project for learning and development.

๐Ÿ™ Acknowledgments

๐Ÿ“ง Support

For issues or questions, please open a GitHub issue or contact the maintainers.


Happy Restaurant Hunting! ๐Ÿ•๐Ÿฃ๐ŸŒฎ๐Ÿ”

About

LLM project to connect to an API and find the best restaurants for a certain food craving in a certain city

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages