Skip to content

MohitGupta0123/GraphRAG-Ebay-User-Aggrement-Chatbot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

39 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🧠 GraphRAG: eBay User Agreement Chatbot

Streamlit Live App Meta LLaMA 3B Neo4j KG Python 3.12 License: MIT

A Knowledge Graph-Powered Conversational AI built to answer legal and policy-related queries from the eBay User Agreement using Neo4j, LLMs (Meta LLaMA 3B), and Memory via FAISS.

🌐 Website - DEMO

Knowledge Graph

πŸ’‘ Project Motivation

Reading long user agreements is painful. This project creates an intelligent chatbot that:

  • Understands natural language queries
  • Retrieves facts from a Neo4j-based Knowledge Graph
  • Enhances responses using memory of past conversations
  • Uses open-source LLMs to generate grounded, concise, and transparent answers

πŸ” End-to-End Architecture

1. 🧱 Steps:

  1. User submits a query via Streamlit UI.
  2. Named Entities are extracted using SpaCy + RE.
  3. Matching triples are fetched from Neo4j KG.
  4. Memory module (FAISS) adds past Q&A context.
  5. Prompt is dynamically injected and sent to LLaMA-3B.
  6. Response is streamed and displayed to the user.

2. 🧠 Knowledge Graph Construction

  • Text source: eBay User Agreement PDF
  • Preprocessing: cleaned and tokenized using SpaCy
  • NER & RE: Custom rules + pre-trained SpaCy models
  • Triplets: Extracted using pattern matching and OpenIE-style RE
  • Storage: JSON + CSV β†’ Loaded into Neo4j (local or Aura Free)
  • Tools: graph_builder.py, KG_creation.ipynb

3. πŸ” Query-to-KG Translation

  • Input query is processed for Named Entities.
  • Synonyms are expanded using Sentence Transformers.
  • KG is queried using Cypher to retrieve matching triplets.
  • Top-k results ranked based on entity similarity & relevance.
  • Implemented in retriever.py using match (s)-[r]->(o) pattern.

4. πŸ’¬ Prompting Strategy

  • Format: [Triples] + [Memory] β†’ Context Window
  • Model: Meta LLaMA-3B (Instruct-tuned)
  • Sent via HF endpoint with streaming

πŸ“Œ Example


System: You are a legal assistant for eBay User Agreement.
Context:

* \[User] may terminate the agreement with 30 days notice.
* \[eBay] may restrict access for violation.
  Memory:
* Q: What if I break the policy? A: Your access may be restricted.
  Question: Can I end the agreement anytime?

Answer:

eBay allows termination with 30 days’ notice. However, immediate termination may depend on specific conditions outlined in Section X.

5. ▢️ Running the Chatbot

  • Install dependencies: pip install -r requirements.txt

  • Add your Hugging Face token in the UI sidebar.

  • Add Neo4j credentials in .streamlit/secrets.toml

  • Run: streamlit run app.py


6. 🧠 Model Details & Streaming

  • Model: Meta LLaMA-3B-Instruct (via HuggingFace)
  • Endpoint: HuggingFace Inference Endpoint (stream=True)
  • Temperature: 0 - 0.2 for factual output
  • Streaming: Enabled to simulate real-time response using requests with stream

πŸš€ Features

βœ… Knowledge Graph-based reasoning

βœ… Memory-augmented retrieval (FAISS)

βœ… Legal/Policy Q&A grounded in real documents

βœ… Streamlit-powered UI with chat history and controls

βœ… Chat save/load functionality

βœ… Real-time LLM responses using HuggingFace inference endpoint


🧱 Project Structure

.
β”œβ”€β”€ app.py                          # Main Streamlit app
β”œβ”€β”€ requirements.txt               # Dependencies
β”œβ”€β”€ create_code.py                 # Code generation helper
β”œβ”€β”€ chat_history.json              # Sample chat history
β”‚
β”œβ”€β”€ Src/                           # Core logic modules
β”‚   β”œβ”€β”€ memory.py                  # Persistent memory using Chroma
β”‚   β”œβ”€β”€ retriever.py               # Entity extractor & KG triple retriever
β”‚   β”œβ”€β”€ prompt_injector.py         # Prompt builder & LLM streaming query
β”‚   └── graph_builder.py           # For KG construction
β”‚
β”œβ”€β”€ Triples/                       # Triplets extracted from the source doc
β”‚   β”œβ”€β”€ graphrag_triplets.csv/json
β”‚   β”œβ”€β”€ triples_raw.json
β”‚   β”œβ”€β”€ triples_structured.json
β”‚   └── knowledge_graph_triplets.json
β”‚
β”œβ”€β”€ KG/                            # Visuals & summaries
β”‚   β”œβ”€β”€ knowledge_graph_image.png
β”‚   └── summary.json
β”‚
β”œβ”€β”€ NER/                           # Extracted named entities
β”‚   └── ner_entities.json
β”‚
β”œβ”€β”€ Data/
β”‚   β”œβ”€β”€ Ebay_user_agreement.pdf
β”‚   └── cleaned_ebay_user_agreement.txt
β”‚
β”œβ”€β”€ Notebooks/                     # Jupyter notebooks for exploration
β”‚   β”œβ”€β”€ KG_creation.ipynb
β”‚   β”œβ”€β”€ preprocessing.ipynb
β”‚   └── graphrag-quering-kg-and-llm-prompting.ipynb
β”‚
β”œβ”€β”€ .streamlit/
β”‚   └── secrets.toml               # API keys & credentials
β”œβ”€β”€ .gitignore
└── README.md

βš™οΈ Setup & Installation

  1. Clone the repository
git clone https://github.com/MohitGupta0123/GraphRAG-Ebay-User-Aggrement-Chatbot.git
cd GraphRAG-Ebay-User-Aggrement-Chatbot
  1. Install dependencies
pip install -r requirements.txt
  1. Token Configuration

This app prompts for your Hugging Face token (HF_TOKEN) securely at runtime in the sidebar.
You no longer need to store the token in secrets.toml.

However, Neo4j credentials are still required in .streamlit/secrets.toml:

NEO4J_URI = "bolt://your_neo4j_uri"
NEO4J_USERNAME = "neo4j"
NEO4J_PASSWORD = "your_password"
NEO4J_DATABASE = "neo4j"
  1. Launch the app
streamlit run app.py

🧠 How It Works

1. User Input

You ask a question like:

"Can I terminate the agreement anytime?"

2. Entity Extraction

Entities like terminate, agreement are extracted.

3. Knowledge Graph Retrieval

Relevant triples from Neo4j are retrieved.

4. Memory Recall

Past similar Q&A are pulled from persistent memory (Faiss).

5. Prompt Generation

Triples + memory form a context which is sent to LLaMA-3B via Hugging Face API.

6. Answer Generation

The LLM answers based only on retrieved facts β€” no hallucination.


πŸ’Ύ Save & Load Chat

You can download your chat as a .json file and re-upload it to continue your session. All retrieved triples and memory are retained across sessions!


πŸ“Έ Demo Snapshots

Knowledge Graph Visualization


πŸ“Œ Tech Stack

  • Frontend: Streamlit
  • LLM: Meta LLaMA-3B-Instruct via HuggingFace
  • Graph: Neo4j (Aura Free or Local)
  • Embeddings: SentenceTransformers
  • Memory Store: FAISS
  • Triplet Extraction: SpaCy / RE Pipelines
  • NER: Custom + pre-trained models

πŸ›‘ Limitations

  • Currently optimized for the eBay User Agreement
  • Requires manual graph building from text
  • Needs HuggingFace token (streaming)

πŸ“¬ Contact

For suggestions or collaboration:


🧠 Acknowledgement

  • GraphRAG research from Meta AI
  • Neo4j Knowledge Graphs
  • LangChain Memory Chains

About

A Knowledge Graph-powered conversational chatbot that answers legal and policy questions from the eBay User Agreement using Neo4j, Faiss, and Meta's LLaMA-3B-Instruct LLM.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors