fjolsvin/chainlit-rag-poc
0
๐ Chainlit RAG POC
๐ Description
This project is a Proof of Concept (POC) for a Retrieval-Augmented Generation (RAG) system using Chainlit. It demonstrates how to build a conversational AI application that can search and retrieve information from a vector database to enhance its responses.
โจ Features
- ๐ค Conversational AI interface powered by Chainlit
- ๐ Retrieval-Augmented Generation (RAG) for enhanced responses
- ๐๏ธ Flexible database backend (SQLite or Turso)
- ๐ Configurable vector database (in-memory or Qdrant)
- ๐ PDF and text file processing
- ๐ Secure authentication system
๐ง Configuration
Create a .env file in the root directory and set the following environment variables:
๐ Required Environment Variables
OPENAI_API_KEY: Your OpenAI API key
๐ Vector Database Configuration
VECTOR_STORE_TYPE: Type of vector store to use (default: "in_memory")- Options: "in_memory", "qdrant"
Qdrant-specific Configuration (if using Qdrant)
QDRANT_URL: URL of your Qdrant instanceQDRANT_API_KEY: API key for QdrantQDRANT_COLLECTION_NAME: Name of the Qdrant collection (default: "chainlit-rag-poc")
๐๏ธ Database Configuration
TURSO_DATABASE_URL: URL for Turso database (optional)TURSO_AUTH_TOKEN: Authentication token for Turso (optional)SQLITE_PATH: Path for SQLite database (default: "./local.db")
๐ Logging Configuration
LOG_LEVEL: Logging level (default: "INFO")LOG_TO_FILE: Whether to log to a file (default: "False")LOG_TO_CONSOLE: Whether to log to console (default: "True")LOG_FILE: Path to log file (default: "app.log")LOG_COLORFUL: Whether to use colorful logs (default: "True")
๐พ Database and Vector Database Operations
The application's behavior changes based on the environment variables:
Database Operations
- If both
TURSO_DATABASE_URLandTURSO_AUTH_TOKENare set, the application will use Turso as the database backend. - If either of these is not set, it will fall back to using a local SQLite database at the path specified by
SQLITE_PATH.
Vector Database Operations
- If
VECTOR_STORE_TYPEis set to "qdrant" and bothQDRANT_URLandQDRANT_API_KEYare provided, the application will use Qdrant as the vector store. - If
VECTOR_STORE_TYPEis "in_memory" or the Qdrant credentials are not provided, it will use an in-memory vector store.
๐ Running the Application
To run the application, use the following command:
poetry run python -m app
This will start the Chainlit server, and you can access the application through your web browser.
๐ Usage Guide
- Start the Application: Run the command mentioned above to start the Chainlit server.
- Access the Web Interface: Open your web browser and navigate to the URL provided in the console (typically
http://localhost:8000).
- Upload a Document: Use the file upload feature to submit a PDF or text document. The system will process and index the document's content.
- Ask Questions: Once the document is processed, you can start asking questions related to the content of the uploaded document.
- Interact with the AI: The AI will use the RAG system to provide informed responses based on the uploaded document and its general knowledge.
- Review Sources: The AI may provide sources or references from the uploaded document to support its answers.
- Continue the Conversation: You can ask follow-up questions or upload additional documents as needed.
๐งฉ Project Structure
app/: Main application directory__main__.py: Entry point of the applicationauth/: Authentication-related moduleschainlit/: Chainlit-specific moduleschat/: Chat-related modulesdatabase/: Database-related modulesembedding/: Embedding-related modulesmodels/: Database modelsprompt/: Prompt-related modulesrag/: RAG-specific modulestext/: Text processing modulesvectordb/: Vector database modules
๐ค Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
