Kotaemon

repository·main·Indexed 12 days ago

https://github.com/cinnamon/kotaemon

An open-source, customizable Retrieval-Augmented Generation (RAG) UI for chatting with documents. It functions as both a ready-to-use application for end users and a development framework for engineers. Key features include hybrid retrieval (full-text and vector), multi-modal document parsing, advanced citations with PDF highlighting, and support for reasoning agents like ReAct and ReWOO. It integrates with LLM providers such as OpenAI, Azure, and Ollama, and supports GraphRAG implementations including NanoGraphRAG, LightRAG, and MS GraphRAG.

Tokens
22.5K
Snippets
59
Records
108
Agent score
95%

What's inside Kotaemon

  1. Overview of kotaemon

    main

    kotaemon is an open-source, customizable Retrieval-Augmented Generation (RAG) UI designed for chatting with documents. It serves two primary audiences:

    • End Users: People who want to use a clean, minimalistic interface to perform QA on their documents using various LLM providers (OpenAI, Azure, Ollama, etc.).
    • Developers: People who want to use kotaemon as a framework to build, customize, and host their own RAG pipelines.

    Key capabilities include hybrid retrieval (full-text and vector), multi-modal document parsing (supporting figures and tables), advanced citations with in-browser PDF highlighting, and support for complex reasoning agents like ReAct and ReWOO.

  2. Key Features of kotaemon

    main

    kotaemon provides a comprehensive set of features for document-based QA:

    • Web UI Hosting: Supports multi-user login, private/public collections, and chat sharing.
    • Model Management: Organize and use both local LLMs (via ollama and llama-cpp-python) and API providers (OpenAI, Azure, Groq, etc.).
    • Hybrid RAG Pipeline: Uses a combination of full-text and vector retrieval with re-ranking for high-quality results.
    • Multi-modal Support: Handles documents containing figures and tables with selectable parsing options.
    • Advanced Citations: Provides detailed citations with relevance scores and highlights within an in-browser PDF viewer.
    • Complex Reasoning: Supports question decomposition and agent-based reasoning (e.g., ReAct, ReWOO).
    • Configurable UI: Allows adjusting retrieval and generation settings, including prompts, directly through the interface.
    • Extensibility: Built on Gradio, allowing for custom UI elements and various indexing strategies (e.g., GraphRAG).
  3. How components work in kotaemon

    main

    In kotaemon, a component is the fundamental building block of a pipeline. Conceptually, a component is a step that takes an input, processes it, and returns an output (similar to a Python function).

    Because components can contain other components as part of their processing logic, a pipeline is simply a nested component. This allows you to compose complex workflows by building larger components out of smaller, reusable ones.

  4. Understand chat scores and evidence

    main

    The Information Panel in the Chat tab provides evidence, citations, and quality scores to help assess the reliability of the LLM's response.

    Score Types

    • Answer confidence: The confidence level reported by the LLM.
    • Relevance score: The overall score between the evidence and the user question.
    • Vectorstore score: Similarity score from vector embedding calculation (shows full-text search if retrieved from a full-text search DB).
    • LLM relevant score: Relevancy score determined by the LLM using a specific prompt.
    • Reranking score: Relevancy score from a Cohere reranking model.

    Note: Generally, the quality hierarchy is: LLM relevant score > Reranking score > Vectorscore. By default, the overall relevance score is derived from the LLM relevant score.

  5. Understand the three types of settings in ktem

    main

    Settings in ktem are categorized into three distinct types based on the stakeholder and use case:

    1. Developer settings: Used for basic application customization (e.g., database URL, cloud configuration, logging configuration, and feature toggles). These are declared within flowsettings.py. Use these if you are deploying ktem to customers or building extensions.
    2. Admin settings: Accessible via the Admin page. These allow administrators to configure low-level features, such as credentials for data sources or specific keys for LLM providers.
    3. User settings: Designed for runtime users to personalize their experience, such as selecting output languages or choosing a reasoning type.
  6. Define a custom pipeline class using BaseComponent

    main

    A pipeline is a class inheriting from kotaemon.base.BaseComponent. It consists of declared arguments (sub-pipelines or primitives) and a run method containing the execution logic.

    Example structure:

    from kotaemon.base import BaseComponent
    
    class MyPipeline(BaseComponent):
        arg1: int
        arg2: str
    
        def run(self, arg3: str):
            return self.arg1 * self.arg2 + arg3
    from kotaemon.base import BaseComponent
    
    
    class SoSimple(BaseComponent):
        arg1: int
        arg2: str
    
        def run(self, arg3: str):
            return self.arg1 * self.arg2 + arg3
  7. Enable local LLMs via .env

    main

    To run models locally (e.g., GGUF format from Hugging Face), set the LOCAL_MODEL variable in your .env file to the absolute path of your model file.

    Hardware Tip: Ensure the model size leaves at least 2 GB of available RAM. For example, if you have 12 GB available, choose a model that uses at most 10 GB.

    LOCAL_MODEL=<full path to your model file>
  8. Launch Kotaemon after initial setup

    main

    To restart the application or apply changes after the initial installation, simply run the OS-specific run_* script again from the scripts folder:

    • Windows: run_windows.bat
    • macOS: run_macos.sh
    • Linux: run_linux.sh
    # Example for Linux
    bash run_linux.sh
  9. Use the Prompt Engineering UI for Simple Pipelines

    main

    The Prompt Engineering UI allows non-technical users (testers, domain experts) to experiment with pipeline parameters (e.g., top_k, temperature) and prompts without modifying code.

    For a Simple Pipeline (one-way execution), the workflow is:

    1. Build the pipeline in Python.
    2. Export the pipeline to a YAML configuration file using the kotaemon promptui export command.
    3. Customize the YAML config to define UI components for inputs, params, outputs, and logs.
    4. Run the UI using the kotaemon promptui run command.
    5. Experiment: Users adjust parameters in the UI, click Run to execute, and click Export to download an Excel file containing the results for comparison.
    # 1. Export the pipeline class to a config file
    $ kotaemon promptui export <module.path.pipelineclass> --output <path/to/config/file.yml>
    
    # 2. Run the Prompt Engineering UI
    $ kotaemon promptui run <path/to/config/file.yml>
  10. Install Kotaemon without Docker

    main

    If you prefer a manual installation, follow these steps:

    1. Clone the repository:

      git clone https://github.com/Cinnamon/kotaemon
      cd kotaemon
    2. Setup the environment (Choose one):

      • Using uv (Recommended):
        uv sync --python 3.10
        source .venv/bin/activate
      • Using conda:
        conda create -n kotaemon python=3.10
        conda activate kotaemon
        pip install -e "libs/kotaemon[all]"
        pip install -e "libs/ktem"
    3. Configure Environment Variables: Create a .env file in the root directory using .env.example as a template. This file populates the database on the first run.

    4. Start the server:

      python app.py

      The default username and password are both admin.

    # Using uv (recommended)
    uv sync --python 3.10
    source .venv/bin/activate
    
    # Start the server
    python app.py