CoolFace
Apppublic

fjolsvin/chainlit-rag-poc

sourceHugging Facempl-2.0updated 2y agoView on Hugging Face
0likes
App README

๐Ÿš€ 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 instance
  • โ€”QDRANT_API_KEY: API key for Qdrant
  • โ€”QDRANT_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_URL and TURSO_AUTH_TOKEN are 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_TYPE is set to "qdrant" and both QDRANT_URL and QDRANT_API_KEY are provided, the application will use Qdrant as the vector store.
  • โ€”If VECTOR_STORE_TYPE is "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

  1. 1.Start the Application: Run the command mentioned above to start the Chainlit server.
  1. 1.Access the Web Interface: Open your web browser and navigate to the URL provided in the console (typically http://localhost:8000).
  1. 1.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.
  1. 1.Ask Questions: Once the document is processed, you can start asking questions related to the content of the uploaded document.
  1. 1.Interact with the AI: The AI will use the RAG system to provide informed responses based on the uploaded document and its general knowledge.
  1. 1.Review Sources: The AI may provide sources or references from the uploaded document to support its answers.
  1. 1.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 application
  • โ€”auth/: Authentication-related modules
  • โ€”chainlit/: Chainlit-specific modules
  • โ€”chat/: Chat-related modules
  • โ€”database/: Database-related modules
  • โ€”embedding/: Embedding-related modules
  • โ€”models/: Database models
  • โ€”prompt/: Prompt-related modules
  • โ€”rag/: RAG-specific modules
  • โ€”text/: Text processing modules
  • โ€”vectordb/: Vector database modules

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.