Skip to content

HiBorn4/graphRag

Repository files navigation

Inventory Graph Chatbot

Visualization

Overview

This project provides an advanced, LLM-powered chatbot for querying and analyzing Mahindra & Mahindra's inventory data using a Neo4j knowledge graph. It leverages LangChain, Azure OpenAI, and custom prompt engineering to enable natural language Q&A, Cypher query generation, and data normalization.

Features

  • Natural Language Chatbot: Ask inventory-related questions in plain English.
  • Automated Cypher Generation: Converts user queries to Cypher for Neo4j.
  • Entity Normalization: Maps user terms to canonical KG forms.
  • Graph Data Transformation: Converts tabular/text data into graph documents.
  • Extensible Prompt Templates: Easily adapt prompts for new use cases.
  • Professional Notebook Workflows: Includes Jupyter notebooks for experimentation and development.

Project Structure

app.py                      # (Optional) App entry point
create_chatbot.ipynb        # Main notebook for chatbot logic
create_kg_new.ipynb         # (Optional) KG creation notebook
main.py                     # Main Python script for end-to-end execution
parse_excel.ipynb           # Data parsing notebook
prompts.py                  # All prompt templates
requirements.txt            # Python dependencies
visualization.png           # Project architecture/graph visualization
__pycache__/                # Python cache files
 data/                      # Inventory data files
 docs/                      # Documentation and schema files

Setup Instructions

1. Clone the Repository

git clone https://github.com/HiBorn4/graphRag.git
cd MahindraMahindra/archive/graphrag

2. Install Python Dependencies

It is recommended to use a virtual environment:

python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

3. Configure Environment Variables

Create a .env file in the project root with the following variables:

NEO4J_URI=neo4j://localhost:7687
NEO4J_USER=neo4j
NEO4J_PASSWORD=your_neo4j_password
AZURE_DEPLOYMENT=your_azure_deployment
AZURE_OPENAI_API_KEY=your_azure_openai_api_key
AZURE_OPENAI_ENDPOINT=your_azure_openai_endpoint
AZURE_OPENAI_VERSION=your_azure_openai_version

4. Prepare Neo4j Database

  • Install Neo4j Community or Aura and start the server.
  • Load your inventory data as per the schema in docs/kg_schema_overview.md or docs/kg_schema_overview3.md.
  • Update the .env file with your Neo4j credentials.

5. Run the Chatbot

Option 1: Jupyter Notebook

  • Open create_chatbot.ipynb or main.py in VS Code or Jupyter Lab.
  • Run cells step by step to interact with the chatbot and see Cypher queries/results.

Option 2: Python Script

python main.py

6. Customization

  • Prompts: Edit prompts.py to adjust normalization or Cypher generation logic.
  • Data: Place new inventory data in the data/ folder and update notebooks/scripts as needed.
  • Visualization: Update visualization.png to reflect your graph structure.

Notebooks

  • create_chatbot.ipynb: End-to-end chatbot logic, entity normalization, Cypher generation, and result analysis.
  • graph_transformer.ipynb: Demonstrates transforming tabular/text data into graph documents using LLMs.
  • parse_excel.ipynb: Utilities for parsing and preparing inventory data.

Example Usage

  • Ask: "What is the difference in Stock in trade count for the company 133-FES from FY24 to FY23?"
  • The system normalizes entities, generates Cypher, queries Neo4j, and returns a human-readable answer.

Troubleshooting

  • Neo4j Connection Errors: Ensure Neo4j is running and credentials are correct in .env.
  • Azure/OpenAI Errors: Verify your API keys and endpoint URLs.
  • Missing Data: Check that your data files are present in the data/ directory and loaded into Neo4j.

License

This project is for internal use at Mahindra & Mahindra. For external use, please contact the project owner.

Contact

For questions or support, contact the project maintainer or your internal IT team.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages