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.
- 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.
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
git clone https://github.com/HiBorn4/graphRag.git
cd MahindraMahindra/archive/graphragIt is recommended to use a virtual environment:
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txtCreate 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
- Install Neo4j Community or Aura and start the server.
- Load your inventory data as per the schema in
docs/kg_schema_overview.mdordocs/kg_schema_overview3.md. - Update the
.envfile with your Neo4j credentials.
- Open
create_chatbot.ipynbormain.pyin VS Code or Jupyter Lab. - Run cells step by step to interact with the chatbot and see Cypher queries/results.
python main.py- Prompts: Edit
prompts.pyto adjust normalization or Cypher generation logic. - Data: Place new inventory data in the
data/folder and update notebooks/scripts as needed. - Visualization: Update
visualization.pngto reflect your graph structure.
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.
- 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.
- 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.
This project is for internal use at Mahindra & Mahindra. For external use, please contact the project owner.
For questions or support, contact the project maintainer or your internal IT team.
