Multi-Session Knowledge Graph QA System with Gradio, FAISS & PyVis

Key Features: ✅ Document Indexing – Upload text documents, extract named entities with spaCy, and build a knowledge graph. ✅ Knowledge Graph Construction – Nodes represent entities, and edges indicate relationships extracted from text. ✅ Sentence Embeddings & Fine-Tuning – Uses SentenceTransformer to create embeddings and contrastive learning for fine-tuning. ✅ FAISS Vector Search – Enables fast retrieval of similar entities using FAISS. ✅ Multi-Session Conversational QA – Each session has its own chat history, and previous messages can be referenced. ✅ Ollama API Integration – Sends prompts to an external API to generate responses based on document and chat…

Category: ,

Description

Key Features:
✅ Document Indexing – Upload text documents, extract named entities with spaCy, and build a knowledge graph.
✅ Knowledge Graph Construction – Nodes represent entities, and edges indicate relationships extracted from text.
✅ Sentence Embeddings & Fine-Tuning – Uses SentenceTransformer to create embeddings and contrastive learning for fine-tuning.
✅ FAISS Vector Search – Enables fast retrieval of similar entities using FAISS.
✅ Multi-Session Conversational QA – Each session has its own chat history, and previous messages can be referenced.
✅ Ollama API Integration – Sends prompts to an external API to generate responses based on document and chat history.
✅ Graph Visualization – PyVis generates an interactive knowledge graph with optional ephemeral chat data.
✅ Session Persistence – Saves and reloads indexed documents and chat history for continued use.

Setup Guide
1. Install Dependencies
Ensure you have Python 3.8+ installed, then install the required packages:

pip install gradio requests spacy networkx numpy faiss-cpu torch sentence-transformers pyvis
You also need to download the spaCy English model:

python -m spacy download en_core_web_sm

 

2. Clone or Download the Code
If you have access to the full project, download it from bel.solutions:

git clone https://github.com/your-repo/knowledge-graph-qa.git
cd knowledge-graph-qa

 

3. Configure the Ollama API Endpoint
Edit the script and update the REMOTE_OLLAMA_API_URL in the configuration section to match your API endpoint:

REMOTE_OLLAMA_API_URL = “http://192.168.1.2:11434”
Ensure your API is running and accessible.

 

 

4. Run the Application
Start the Gradio UI by running:

python app.py
This will launch a local web interface where you can:
✅ Upload documents
✅ Build the knowledge graph
✅ Start multi-session conversations
✅ Visualize graphs

 

 

5. Saving & Loading Sessions
Save all sessions: The system automatically saves knowledge graphs, embeddings, and chat history.
Reload saved data: When relaunching, previously indexed documents and conversation histories are available.

 

 

6. Example Usage
Upload a document (e.g., example.txt)
Ask a question related to the document
View retrieved document snippets and chat history
See the knowledge graph visualization

 

🚀 Get the Full Code & Documentation: Available at bel.solutions.