@@ -33,17 +33,19 @@ This system is designed to provide a seamless and informative question-answering
## Features
-**Offline Operation:** Functions entirely without an internet connection, ensuring data privacy and availability.
-**Multilingual Support:** Handles questions and provides answers in multiple languages (Spanish, French, German, Thai, Russian, Arabic, Portuguese, Mandarin).
-**Contextual Understanding:** Maintains conversation history within chat sessions to provide more relevant and coherent responses to follow-up questions.
-**Self-Correction:** Employs a retry mechanism to iteratively refine answers, minimizing hallucinations and improving accuracy.
-**Terminal-Based Chat Interface:** Offers a user-friendly, real-time chat interface for interaction.
-**UID Tracking & Database:** Assigns unique identifiers to each interaction, facilitating tracking, analysis, and debugging.
-**Caching:** Enhances performance by storing and reusing previous results.
-**Document Referencing:** Provides transparency by citing the sources used to generate answers.
-**Efficient Multilingual Tokenizer:** Utilizes SentencePiece for efficient handling of multiple languages.
-**Offline LLM:** Leverages the Vicuna-7B model for powerful language understanding and answer generation capabilities in an offline setting.
* Offline Operation: Functions entirely without an internet connection, ensuring data privacy and availability.
* Multilingual Support: Handles questions and provides answers in multiple languages (Spanish, French, German, Thai, Russian, Arabic, Portuguese, Mandarin).
* Contextual Understanding: Maintains conversation history within chat sessions to provide more relevant and coherent responses to follow-up questions.
* Self-Correction: Employs a retry mechanism to iteratively refine answers, minimizing hallucinations and improving accuracy.
* Terminal-Based Chat Interface: Offers a user-friendly, real-time chat interface for interaction.
* UID Tracking & Database: Assigns unique identifiers to each interaction, facilitating tracking, analysis, and debugging.
* Caching: Enhances performance by storing and reusing previous results.
* Document Referencing: Provides transparency by citing the sources used to generate answers.
* Efficient Multilingual Tokenizer: Utilizes SentencePiece for efficient handling of multiple languages.
* Offline LLM: Leverages the Vicuna-7B model for powerful language understanding and answer generation capabilities in an offline setting.
@@ -67,7 +69,7 @@ The system's modular architecture comprises interconnected components, each fulf
* Loads offline translation models (MarianMT) for supported language pairs using the SentencePiece tokenizer
* Loads the local embedded document collection using the specified embedding model (sentence-transformers/all-MiniLM-L6-v2)
* Initializes the database connection and creates the necessary table
*Sets up an in-memory cache (can be replaced with a more robust solution)
* Sets up a Redis cache
* Loads the offline LLM (Vicuna-7B)
### `Tasks` (`tasks.py`)
@@ -83,7 +85,7 @@ The system's modular architecture comprises interconnected components, each fulf
*`translate_to_user_language_task`: Translates the answer back to the original language if needed
*`display_answer_in_chat_task`: Displays the answer in the chat interface and updates the database
***Key Considerations:**
*The `tool_code` blocks within each task contain the actual logic for performing the task. You'll need to fill in the placeholders with your specific implementations
* The `tool_code` blocks within each task contain the actual logic for performing the task.
* The `args` dictionaries define how data flows between tasks, specifying which outputs from one task are passed as inputs to another
### Tools
@@ -196,7 +198,6 @@ The system's modular architecture comprises interconnected components, each fulf
```
***Optional Libraries:**
* If you plan to implement the email functionality in the future, you'll also need to install libraries for interacting with the Outlook 365 API (e.g., `requests_oauthlib` and `microsoft-graph`).
* If you choose a different caching solution than the basic in-memory cache, install the necessary library for that (e.g., `redis` for Redis).
@@ -205,7 +206,7 @@ The system's modular architecture comprises interconnected components, each fulf
@@ -217,7 +218,7 @@ The system's modular architecture comprises interconnected components, each fulf
3.**Create a virtual environment:**
```bash
python -m venv myenv # Replace 'myenv' with your preferred environment name
python -m venv offlineqa-env # Create an environment named 'offlineqa-env'
```
4.**Activate the virtual environment:**
@@ -225,13 +226,13 @@ The system's modular architecture comprises interconnected components, each fulf
* **On Windows:**
```bash
myenv\Scripts\activate
offlineqa-env\Scripts\activate
```
* **On macOS/Linux:**
```bash
source myenv/bin/activate
source offlineqa-env/bin/activate
```
5.**Install dependencies using the provided `requirements.txt` file:**
@@ -330,6 +331,63 @@ The system's modular architecture comprises interconnected components, each fulf
* This code snippet demonstrates how to load documents from the `uploads` folder, split them into chunks, generate embeddings using the `all-MiniLM-L6-v2` model (recommended for Vicuna), and store them in a FAISS index.
8.**Download the spaCy language model and enable the coherence pipe:**
```bash
python -m spacy download en_core_web_sm
python -m spacy_experimental.coref.download en # Download the coreference resolution data
```
9.**Set up Redis (if using Redis for caching):**
* **On Windows:** Download and install Redis from the official website: [https://redis.io/download/](https://redis.io/download/). Follow the instructions provided on the website for Windows installation.
* **On macOS:**
```bash
brew install redis
```
* **On Ubuntu:**
```bash
sudo apt update
sudo apt install redis-server
```
* **Start the Redis server:** Follow the platform-specific instructions to start the Redis server.
10.**Set up PostgreSQL (if using PostgreSQL for the database):**
* **On Windows:** Download and install PostgreSQL from the official website: [https://www.postgresql.org/download/](https://www.postgresql.org/download/). Follow the instructions provided on the website for Windows installation.
* **On macOS:**
```bash
brew install postgresql
brew services start postgresql
```
* **On Ubuntu:**
```bash
sudo apt update
sudo apt install postgresql postgresql-contrib
```
* **Create a database and user:**
```bash
sudo -u postgres psql # Access PostgreSQL shell
CREATE DATABASE my_qna_db;
CREATE USER my_qna_user WITH ENCRYPTED PASSWORD 'your_password';
GRANT ALL PRIVILEGES ON DATABASE my_qna_db TO my_qna_user;
\q # Exit the shell
```
* Update the database connection details in the `_initialize_database` method in `config.py` with your PostgreSQL credentials.
11.**Start Redis and PostgreSQL servers (if applicable):**
* **On Windows:** Use the services management console or the command line to start the Redis and PostgreSQL services.
* **On macOS:**
```bash
brew services start redis
brew services start postgresql
```
* **On Ubuntu:**
```bash
sudo systemctl start redis-server
sudo systemctl start postgresql
```
### Configuration
@@ -342,7 +400,7 @@ The system's modular architecture comprises interconnected components, each fulf
2.**Tool Implementations**
* In `document_answerer.py`, ensure the `_run` method uses your actual offline LLM interface.
* Customize the `SelfCorrectiveAgent` in `self_corrective_agent.py` with your desired evaluation logic and thresholds.
*Implement the chat interface logic in `chat_input_tool.py` and the `display_answer_in_chat_task` in `tasks.py` using the `curses` library or a similar approach.
*The chat interface logic in `chat_input_tool.py` and the `display_answer_in_chat_task` in `tasks.py`are already implemented using the `curses` library.
### Running the System
@@ -391,9 +449,6 @@ This project is licensed under the [MIT License](LICENSE)
* If you have domain-specific data, explore fine-tuning the Vicuna-7B LLM to enhance its accuracy and relevance for your particular use case.
***Enhance Self-Correction:**
* Investigate and implement more advanced techniques for hallucination detection, coherence assessment, and fact-checking to further improve the quality of generated answers.
***Implement Robust Caching:**
* Replace the simple in-memory cache with a more production-ready solution like Redis or Memcached, especially if you anticipate high volumes of interactions.
* Implement proper cache expiration and invalidation strategies to manage memory usage and ensure answer freshness.
***Expand Document Collection:**
* Continuously update and expand your embedded document collection to cover a wider range of topics and domains, making the system more knowledgeable and versatile.