Knowledge2Model/GraphRAG
Hitesh Karakoti e060684acf updated 2026-05-13 01:43:23 +02:00
..
Graph_Neo4j_09.10.25 clean up code 2025-10-09 11:11:01 +02:00
Graph_Neo4j_27.01.26 Add Neo4j backup dumps 2026-01-27 18:14:51 +01:00
Graph_Neo4j_30.04.26 updated database 2026-05-13 01:43:05 +02:00
embedding Updated 2026-01-27 18:16:00 +01:00
old_neo4j clean up code 2025-10-09 11:11:01 +02:00
Readme.md Updated Workflow 2025-10-08 01:35:10 +02:00
chatbot_backend.py Update 2025-12-01 17:10:38 +05:30
chatbot_frontend.html add v1 Graph RAG 2025-06-03 07:23:41 +02:00
db2annoy.py Added model health status 2025-10-07 21:09:24 +02:00
db2neo4j.py Updated 2026-01-27 18:11:09 +01:00
huggingface2.db updated 2026-05-13 01:43:23 +02:00
semantic_search.py update v1 2025-08-03 23:22:25 +02:00

Readme.md

README

This repository contains scripts and tools for processing, indexing, and querying a SQL-based knowledge graph, plus a simple chat interface. Below is an overview of each component and instructions for exporting/importing the Neo4j database.


Scripts

Pipeline Flow

Stage 1: Data Preparation

  1. db2annoy.py - Preprocessing
    • Reads models from SQLite database
    • Generates semantic embeddings using sentence transformers
    • Builds and saves Annoy index for fast similarity search
    • Outputs: model_metadata.json, model_embeddings.npy, models_index.ann, model_texts.npy.

Stage 2: Graph Database Setup

  1. db2neo4j.py - SQL → Neo4j Conversion
    • Transfers model data from SQLite to Neo4j graph database
    • Creates nodes (Model, Problem, Library, Tag, Metric, HealthStatus)

Stage 3: Backend Service

  1. chatbot_backend.py - Flask Backend (RAG Pipeline)
    • Implements two-stage retrieval:
      1. Semantic search using Annoy index (fast similarity matching)
      2. Graph queries using Neo4j (relationship-based filtering)
    • Connects to LLM (LMStudio/Ollama) for natural language generation

Stage 4: User Interface

  1. chatbot_frontend.html - Web Interface
    • Minimal chat UI for interacting with the backend
    • Sends queries to Flask backend and displays responses

Testing & Debugging Tools

  • semantic_search.py - Standalone Search Tester
    • Tests the Annoy index independently without running the full pipeline
    • Useful for debugging semantic search without Neo4j or LLM

Workflow Summary

Setup (run once or when data changes):

1. python db2annoy.py      # Build embeddings
2. python db2neo4j.py      # Populate Neo4j

Important Notes

Large Generated Files

The following files are generated by db2annoy.py and are not included in the repository due to their size:

File Size Purpose
model_embeddings.npy ~127 MB Dense vector embeddings for semantic search
model_texts.npy ~828 MB Original concatenated text from models
models_index.ann ~151 MB Annoy index structure for fast retrieval
model_metadata.json Small Model IDs and metadata for results

Neo4j Database Dump & Restore

Export (Dump)

# Replace the backup_neo4j with the updated backup folder name
sudo neo4j-admin dump system \         
  --to-path=<path>/Knowledge2Model/GraphRAG/backup_neo4j

sudo neo4j-admin dump neo4j \
  --to-path=<path>/Knowledge2Model/GraphRAG/backup_neo4j

Import (Load)

# Replace the backup_neo4j with the updated backup folder name
sudo neo4j-admin database load system \
  --from-path=<path>/Knowledge2Model/GraphRAG/backup_neo4j \
  --overwrite-destination=true

sudo neo4j-admin database load neo4j \
  --from-path=<path>/Knowledge2Model/GraphRAG/backup_neo4j \
  --overwrite-destination=true

sudo chown -R neo4j:neo4j /var/lib/neo4j/data

Neo4j Credentials

Set environment variables or update your .env file:

NEO4J_URI="bolt://localhost:7687"
NEO4J_USER="neo4j"
NEO4J_PASSWORD="12345678"