### Install RAGLight Package (Bash) Source: https://raglight.mintlify.app/overview/getting-started Installs the RAGLight library from PyPI using pip. This is the primary installation step for using RAGLight. ```bash pip install raglight ``` -------------------------------- ### Install and Run Raglight Serve Source: https://raglight.mintlify.app/documentation/rest-api Installs the raglight package and starts the FastAPI server for the RAG pipeline. The server defaults to port 8000 and can be configured via environment variables. ```bash pip install raglight raglight serve ``` -------------------------------- ### Launch RAGLight CLI Chat Wizard (Bash) Source: https://raglight.mintlify.app/overview/getting-started Initiates the interactive RAGLight CLI wizard for setting up a RAG pipeline. The wizard guides users through document selection, model choices, and configuration. ```bash raglight chat ``` -------------------------------- ### Example Usage of GitHubSource Source: https://raglight.mintlify.app/documentation/knowledge Shows an example of creating a GitHubSource instance. This involves providing the repository URL and optionally specifying a branch. The content of the specified GitHub repository is then treated similarly to a local folder. ```python from raglight.models.data_source_model import GitHubSource source = GitHubSource( url="https://github.com/Bessouat40/RAGLight", branch="main", ) ``` -------------------------------- ### Install and Run RAGLight CLI Commands Source: https://raglight.mintlify.app/ This snippet demonstrates how to install the RAGLight Python package and use its command-line interface (CLI) for various functionalities. It covers launching an interactive chat setup, an optional agentic chat mode, and deploying RAGLight as a REST API without writing custom code. Ensure you have Python and pip installed. ```bash # Install RAGLight pip install raglight # Launch interactive RAG setup raglight chat # Optional Agentic CLI raglight agentic-chat # Deploy as a REST API (no code required) raglight serve ``` -------------------------------- ### Start Ollama Server (Bash) Source: https://raglight.mintlify.app/overview/getting-started Starts the Ollama local LLM server. This command is necessary for RAGLight to connect to the Ollama provider. ```bash ollama serve ``` -------------------------------- ### Example .env File for RAGLight Configuration Source: https://raglight.mintlify.app/documentation/settings Demonstrates an example `.env` file for configuring RAGLight, showing how to set custom endpoints for services like Ollama and API keys for remote providers like OpenAI. This file should be placed in your project's root directory. ```bash # Use a custom Ollama instance on another machine OLLAMA_CLIENT_URL=http://192.168.1.50:11434 # OpenAI Fallback OPENAI_API_KEY=sk-proj-12345... ``` -------------------------------- ### Full Example: RAGPipeline with Hybrid Search Source: https://raglight.mintlify.app/documentation/hybrid-search This comprehensive example shows how to set up and run a RAG pipeline with hybrid search enabled. It configures `VectorStoreConfig` for hybrid search, defines `RAGConfig` with a knowledge base, initializes `RAGPipeline`, builds it, and then generates a response to a query. Logging is also set up. ```python from raglight.rag.simple_rag_api import RAGPipeline from raglight.config.rag_config import RAGConfig from raglight.config.vector_store_config import VectorStoreConfig from raglight.config.settings import Settings from raglight.models.data_source_model import FolderSource Settings.setup_logging() vector_store_config = VectorStoreConfig( embedding_model=Settings.DEFAULT_EMBEDDINGS_MODEL, provider=Settings.HUGGINGFACE, database=Settings.CHROMA, persist_directory="./defaultDb", collection_name=Settings.DEFAULT_COLLECTION_NAME, search_type=Settings.SEARCH_HYBRID, ) config = RAGConfig( llm=Settings.DEFAULT_LLM, provider=Settings.OLLAMA, knowledge_base=[FolderSource(path="./data")], k=5, ) pipeline = RAGPipeline(config, vector_store_config) pipeline.build() response = pipeline.generate("What are the key concepts in these documents?") print(response) ``` -------------------------------- ### Install Ollama and Pull Model (Bash) Source: https://raglight.mintlify.app/overview/getting-started Installs Ollama, a recommended local LLM provider, and pulls the llama3 model. Ensure Ollama is running before proceeding. ```bash ollama pull llama3 ``` -------------------------------- ### Query RAG Pipeline (Python) Source: https://raglight.mintlify.app/overview/getting-started Queries the built RAG pipeline with a given question and prints the generated response. This demonstrates how to interact with the pipeline after it's built. ```python response = pipeline.generate( "What is this project about?" ) print(response) ``` -------------------------------- ### Initialize RAG Pipeline (Python) Source: https://raglight.mintlify.app/overview/getting-started Initializes the RAGPipeline with specified knowledge base, model name, provider, and retrieval count (k). It configures the core components of the RAG system. ```python from raglight.rag.simple_rag_api import RAGPipeline from raglight.config.settings import Settings pipeline = RAGPipeline( knowledge_base=knowledge_base, model_name="llama3", provider=Settings.OLLAMA, k=5 ) ``` -------------------------------- ### Build RAG Pipeline (Python) Source: https://raglight.mintlify.app/overview/getting-started Builds the RAG pipeline by ingesting documents, generating embeddings, and storing them in the vector database. This step prepares the pipeline for querying. ```python pipeline.build() ``` -------------------------------- ### Build and Query Basic RAG Pipeline in Python Source: https://raglight.mintlify.app/examples/basic This Python script demonstrates the core functionality of RAGLight for building a basic Retrieval-Augmented Generation (RAG) pipeline. It configures settings, defines a knowledge base from a local folder, sets up a vector store using Ollama and ChromaDB, builds the pipeline by ingesting documents, and finally queries the pipeline to answer a question based on the provided documents. Dependencies include the raglight library. ```python from raglight.rag.simple_rag_api import RAGPipeline from raglight.config.settings import Settings from raglight.config.rag_config import RAGConfig from raglight.config.vector_store_config import VectorStoreConfig from raglight.models.data_source_model import FolderSource # 1. Initialize Settings Settings.setup_logging() # 2. Configure the vector store (embeddings + ChromaDB) vector_store_config = VectorStoreConfig( embedding_model=Settings.DEFAULT_EMBEDDINGS_MODEL, provider=Settings.HUGGINGFACE, database=Settings.CHROMA, persist_directory="./defaultDb", collection_name=Settings.DEFAULT_COLLECTION_NAME, ) # 3. Configure the RAG pipeline (LLM + retrieval) config = RAGConfig( provider=Settings.OLLAMA, llm=Settings.DEFAULT_LLM, k=5, knowledge_base=[FolderSource(path="./data")], ) # 4. Build the Pipeline (ingests documents and creates the vector store) pipeline = RAGPipeline(config, vector_store_config) pipeline.build() # 5. Ask a Question response = pipeline.generate("What are the key takeaways from these documents?") print("\nšŸ¤– Answer:", response) ``` -------------------------------- ### Example Usage of FolderSource Source: https://raglight.mintlify.app/documentation/knowledge Demonstrates how to instantiate and use the FolderSource class. A FolderSource object is created with a path pointing to a local directory './data/knowledge_base'. When used in a pipeline, all files within this folder are processed. ```python from raglight.models.data_source_model import FolderSource source = FolderSource(path="./data/knowledge_base") ``` -------------------------------- ### Configure Default Embeddings with Python Source: https://raglight.mintlify.app/documentation/embeddings Sets up a default vector store configuration using HuggingFace embeddings and Chroma database. This is a minimal example to get started with local embeddings. ```python from raglight.config.vector_store_config import VectorStoreConfig from raglight.config.settings import Settings vector_store_config = VectorStoreConfig( embedding_model=Settings.DEFAULT_EMBEDDINGS_MODEL, provider=Settings.HUGGINGFACE, database=Settings.CHROMA, persist_directory="./defaultDb", collection_name=Settings.DEFAULT_COLLECTION_NAME, ) ``` -------------------------------- ### Configure Raglight Serve via Environment Variables Source: https://raglight.mintlify.app/documentation/rest-api Sets up environment variables to configure the RAG pipeline, including LLM provider, model, embeddings, ChromaDB settings, and more. This example uses Mistral LLM and a remote ChromaDB instance. ```env RAGLIGHT_LLM_PROVIDER=Mistral RAGLIGHT_LLM_MODEL=mistral-small-latest RAGLIGHT_EMBEDDINGS_PROVIDER=HuggingFace RAGLIGHT_EMBEDDINGS_MODEL=all-MiniLM-L6-v2 RAGLIGHT_CHROMA_HOST=chromadb RAGLIGHT_CHROMA_PORT=8000 RAGLIGHT_COLLECTION=production ``` -------------------------------- ### Define Knowledge Base Folder Source (Python) Source: https://raglight.mintlify.app/overview/getting-started Defines the knowledge base for the RAG pipeline using a FolderSource. This specifies the local directory containing the documents to be indexed. ```python from raglight.models.data_source_model import FolderSource knowledge_base = [ FolderSource(path="./data") # Folder containing your documents ] ``` -------------------------------- ### Enable Chat UI with Raglight Serve Source: https://raglight.mintlify.app/documentation/rest-api Starts the raglight serve with an integrated Streamlit chat UI. The UI is accessible on a separate port and shares configuration with the API. ```bash raglight serve --ui ``` -------------------------------- ### GET /collections Source: https://raglight.mintlify.app/documentation/rest-api List the available ChromaDB collections. ```APIDOC ## GET /collections ### Description List the available ChromaDB collections. ### Method GET ### Endpoint /collections ### Parameters *None* ### Response #### Success Response (200) - **collections** (array of strings) - A list of names of the available ChromaDB collections. #### Response Example ```json { "collections": ["default", "project_x"] } ``` ``` -------------------------------- ### Deploy RAGLight with Docker Compose Source: https://raglight.mintlify.app/documentation/rest-api This section provides bash commands for deploying RAGLight using Docker Compose. It includes steps to copy and edit the environment file, start the Docker stack, ingest documents via upload, and query the API. ```bash cd examples/serve_example cp .env.example .env ``` ```bash docker-compose up ``` ```bash curl -X POST http://localhost:8000/ingest/upload \ -F "files=@./my_document.pdf" ``` ```bash curl -X POST http://localhost:8000/generate \ -H "Content-Type: application/json" \ -d '{"question": "Summarize the document"}' ``` -------------------------------- ### POST /generate Source: https://raglight.mintlify.app/documentation/rest-api Ask a question to the RAG pipeline to get an answer based on the indexed documents. ```APIDOC ## POST /generate ### Description Ask a question to the RAG pipeline. ### Method POST ### Endpoint /generate ### Parameters #### Request Body - **question** (string) - Required - The question to ask the RAG pipeline. ### Request Example ```json { "question": "What is RAGLight?" } ``` ### Response #### Success Response (200) - **answer** (string) - The answer generated by the RAG pipeline. #### Response Example ```json { "answer": "RAGLight is a lightweight Python framework for RAG..." } ``` ``` -------------------------------- ### RAG Pipeline with Google Gemini (Python) Source: https://raglight.mintlify.app/documentation/llm-providers Provides a complete example of setting up and running a RAG pipeline using Google Gemini for both embeddings and generation. This involves configuring data sources, vector stores, and the RAG configuration itself. ```python from raglight.rag.simple_rag_api import RAGPipeline from raglight.models.data_source_model import GitHubSource from raglight.config.settings import Settings from raglight.config.rag_config import RAGConfig from raglight.config.vector_store_config import VectorStoreConfig Settings.setup_logging() # 1. Define Source (e.g., GitHub Repo) knowledge_base = [ GitHubSource(url="https://github.com/Bessouat40/RAGLight") ] # 2. Configure Vector Store (Embeddings) # We use Gemini for embeddings here, but could use Settings.HUGGINGFACE vector_store_config = VectorStoreConfig( provider=Settings.GOOGLE_GEMINI, embedding_model=Settings.GEMINI_EMBEDDING_MODEL, database=Settings.CHROMA, persist_directory="./defaultDb", collection_name="gemini_collection", ) # 3. Configure RAG (Generation) config = RAGConfig( provider=Settings.GOOGLE_GEMINI, llm=Settings.GEMINI_LLM_MODEL, knowledge_base=knowledge_base, api_base=Settings.DEFAULT_GOOGLE_CLIENT # Optional if env var is set ) # 4. Build & Run pipeline = RAGPipeline(config, vector_store_config) pipeline.build() response = pipeline.generate( "How can I create a RAGPipeline using python? Show me code." ) print(response) ``` -------------------------------- ### Direct LLM Usage with Ollama (Python) Source: https://raglight.mintlify.app/documentation/llm-providers Demonstrates how to set up and use the Ollama LLM provider directly via the Builder pattern for testing prompts or models without retrieval. It requires the 'raglight' library and basic Ollama setup. ```python from raglight.rag.builder import Builder from raglight.config.settings import Settings # 1. Setup Settings.setup_logging() model = "llama3" # 2. Build LLM (No retrieval) llm = ( Builder() .with_llm( provider=Settings.OLLAMA, model_name=model, system_prompt=Settings.DEFAULT_SYSTEM_PROMPT ) .build_llm() ) # 3. Chat Loop print(llm.generate({"question": "Explain quantum computing in one sentence."}) ``` -------------------------------- ### Configure Agentic RAG with MCP Integration Source: https://raglight.mintlify.app/documentation/agentic-rag Shows an example of configuring AgenticRAGConfig to integrate with external tools via MCP servers. This allows the agent to execute code, query databases, or fetch live data when deemed relevant. ```python config = AgenticRAGConfig( provider=Settings.OPENAI, model="gpt-4o", k=10, mcp_config=[ {"url": "http://127.0.0.1:8001/sse"} ], ) ``` -------------------------------- ### Customize Chat UI Port Source: https://raglight.mintlify.app/documentation/rest-api Starts the raglight serve with the chat UI on a custom port (3000) while the API remains on the default port (8000). ```bash raglight serve --ui --port 8000 --ui-port 3000 ``` -------------------------------- ### Configure Ollama Local Embeddings with Python Source: https://raglight.mintlify.app/documentation/embeddings Integrates RAGLight with a local Ollama setup for embeddings. Assumes Ollama is running and provides an embeddings model. ```python from raglight.config.vector_store_config import VectorStoreConfig from raglight.config.settings import Settings vector_store_config = VectorStoreConfig( embedding_model="nomic-embed-text", provider=Settings.OLLAMA, database=Settings.CHROMA, persist_directory="./defaultDb", collection_name=Settings.DEFAULT_COLLECTION_NAME, api_base=Settings.DEFAULT_OLLAMA_CLIENT, ) ``` -------------------------------- ### Configure Raglight Serve with CLI Options Source: https://raglight.mintlify.app/documentation/rest-api Demonstrates how to customize the 'raglight serve' command using CLI options such as host, port, number of workers, and enabling the chat UI. ```bash raglight serve --host 127.0.0.1 --port 8080 --workers 4 ``` -------------------------------- ### Check API Health Status Source: https://raglight.mintlify.app/documentation/rest-api Sends a GET request to the /health endpoint to verify the status of the running raglight serve API. ```bash curl http://localhost:8000/health ``` -------------------------------- ### Implement Multimodal RAG Pipeline with Python Source: https://raglight.mintlify.app/examples/multimodal This Python script demonstrates how to set up a RAGLight pipeline that ingests PDFs with images. It involves instantiating a VLM (like llava via Ollama), configuring custom processors to use VlmPDFProcessor, building the vector store, ingesting documents from a specified path, and finally building the RAG pipeline for querying visual content. ```python from raglight.rag.builder import Builder from raglight.config.settings import Settings from raglight.document_processing.vlm_pdf_processor import VlmPDFProcessor from raglight.llm.ollama_model import OllamaModel from raglight.models.data_source_model import FolderSource Settings.setup_logging() # 1. Instantiate a VLM (here: llava via Ollama) vlm = OllamaModel( model_name="llava", system_prompt="You are a technical documentation visual assistant.", ) # 2. Override the default PDF processor with the VLM-based one custom_processors = { "pdf": VlmPDFProcessor(vlm), } # 3. Build the vector store with the custom processor vector_store = ( Builder() .with_embeddings(Settings.HUGGINGFACE, model_name=Settings.DEFAULT_EMBEDDINGS_MODEL) .with_vector_store( Settings.CHROMA, persist_directory="./defaultDb", collection_name=Settings.DEFAULT_COLLECTION_NAME, custom_processors=custom_processors, ) .build_vector_store() ) # 4. Ingest your PDFs vector_store.ingest(data_path="./technical_manuals") # 5. Build the full RAG pipeline and query rag = ( Builder() .with_embeddings(Settings.HUGGINGFACE, model_name=Settings.DEFAULT_EMBEDDINGS_MODEL) .with_vector_store( Settings.CHROMA, persist_directory="./defaultDb", collection_name=Settings.DEFAULT_COLLECTION_NAME, custom_processors=custom_processors, ) .with_llm(Settings.OLLAMA, model_name="llava") .build_rag(k=5) ) response = rag.generate("Describe the architecture diagram on page 3.") print(response) ``` -------------------------------- ### Combine Multiple Knowledge Sources Source: https://raglight.mintlify.app/documentation/knowledge Illustrates how to use multiple knowledge sources, such as FolderSource and GitHubSource, within a single pipeline. These sources are combined into a list, allowing RAGLight to ingest data from various locations into the same vector store. ```python from raglight.models.data_source_model import FolderSource, GitHubSource knowledge_base = [ FolderSource(path="./docs"), GitHubSource(url="https://github.com/Bessouat40/RAGLight"), ] ``` -------------------------------- ### Get Default Ignored Folders in Python Source: https://raglight.mintlify.app/documentation/settings Retrieves a list of directories that RAGLight automatically ignores when ingesting data using FolderSource. This helps maintain a clean index by excluding common build, cache, and system directories. ```python from raglight.settings import Settings # Returns a list of ignored directories ignored_list = Settings.DEFAULT_IGNORE_FOLDERS print(ignored_list) ``` -------------------------------- ### Integrate Sources with RAGPipeline Build Phase Source: https://raglight.mintlify.app/documentation/knowledge Demonstrates the integration of knowledge sources into the RAGLight pipeline during the 'build()' phase. A RAGConfig is created with a list of sources, and then a RAGPipeline is initialized and built. During this process, loaders are resolved, files are ingested, and embeddings are computed. ```python from raglight.rag.simple_rag_api import RAGPipeline from raglight.config.rag_config import RAGConfig config = RAGConfig( knowledge_base=[ FolderSource(path="./data"), GitHubSource(url="https://github.com/Bessouat40/RAGLight"), ] ) pipeline = RAGPipeline(config, vector_store_config) pipeline.build() ``` -------------------------------- ### Build a Basic RAG Pipeline with RAGLight (Python) Source: https://raglight.mintlify.app/documentation/rag Demonstrates how to create a RAG pipeline using the high-level RAGPipeline API. This approach is suitable for quick prototyping and requires minimal boilerplate code. It configures knowledge sources, a vector store, and an LLM, then builds and queries the pipeline. ```python from raglight.rag.simple_rag_api import RAGPipeline from raglight.models.data_source_model import FolderSource, GitHubSource from raglight.config.settings import Settings from raglight.config.rag_config import RAGConfig from raglight.config.vector_store_config import VectorStoreConfig Settings.setup_logging() knowledge_base = [ FolderSource(path="./data/knowledge_base"), GitHubSource(url="https://github.com/Bessouat40/RAGLight"), ] vector_store_config = VectorStoreConfig( embedding_model=Settings.DEFAULT_EMBEDDINGS_MODEL, provider=Settings.HUGGINGFACE, database=Settings.CHROMA, persist_directory="./defaultDb", collection_name=Settings.DEFAULT_COLLECTION_NAME, ) config = RAGConfig( llm=Settings.DEFAULT_LLM, provider=Settings.OLLAMA, knowledge_base=knowledge_base, k=5, ) pipeline = RAGPipeline(config, vector_store_config) pipeline.build() response = pipeline.generate( "How can I create an easy RAGPipeline using RAGLight?" ) print(response) ``` -------------------------------- ### POST /ingest Source: https://raglight.mintlify.app/documentation/rest-api Index documents into the vector store from local folders, specific files, or a GitHub repository. ```APIDOC ## POST /ingest ### Description Index documents into the vector store. Supports three sources — combinable in a single call. ### Method POST ### Endpoint /ingest ### Parameters #### Request Body - **data_path** (string) - Optional - Path to a local folder containing documents to ingest. - **file_paths** (array of strings) - Optional - An array of absolute paths to specific files to ingest. - **github_url** (string) - Optional - The URL of a GitHub repository to ingest. - **github_branch** (string) - Optional - The branch of the GitHub repository to ingest. Defaults to 'main'. *Note: At least one of `data_path`, `file_paths`, or `github_url` must be provided.* ### Request Example (Local folder) ```json { "data_path": "./my_documents" } ``` ### Request Example (Specific files) ```json { "file_paths": ["/absolute/path/to/file.pdf"] } ``` ### Request Example (GitHub repository) ```json { "github_url": "https://github.com/Bessouat40/RAGLight", "github_branch": "main" } ``` ### Response *No specific success response body is detailed in the documentation, but the operation is expected to complete without errors.* ``` -------------------------------- ### Direct LLM Usage with LMStudio (Python) Source: https://raglight.mintlify.app/documentation/llm-providers Shows how to configure and utilize the LMStudio LLM provider directly using the Builder pattern. This is useful for testing prompts and models locally. Ensure your LMStudio server is running and the model name matches. ```python from raglight.rag.builder import Builder from raglight.config.settings import Settings Settings.setup_logging() llm = ( Builder() .with_llm( provider=Settings.LMSTUDIO, model_name="hermes-2-pro", # Match your loaded model system_prompt=Settings.DEFAULT_SYSTEM_PROMPT, # Ensure this matches your LMStudio Local Server config api_base=Settings.DEFAULT_LMSTUDIO_CLIENT, ) .build_llm() ) print(llm.generate({"question": "Hello from RAGLight via LMStudio!"}) ``` -------------------------------- ### RAGLight API Overview Source: https://raglight.mintlify.app/documentation/rag An overview of the RAGLight API, explaining its core concepts and different approaches. ```APIDOC ## Summary * RAG pipelines retrieve documents before generating answers * RAGLight offers a simple (`RAGPipeline`) and an advanced (Builder) API * Both approaches share the same core logic * Choose simplicity or control depending on your use case ``` -------------------------------- ### Set Google Gemini API Key Source: https://raglight.mintlify.app/documentation/embeddings Environment variable configuration for the Google Gemini API key. ```bash export GEMINI_API_KEY=your_key ``` -------------------------------- ### Build Agentic RAG Pipeline with Simple API Source: https://raglight.mintlify.app/documentation/agentic-rag Demonstrates the basic usage of AgenticRAGPipeline for creating reasoning-aware retrieval pipelines with minimal boilerplate. It configures knowledge base, vector store, and agent settings before building and generating a response. ```python from raglight.rag.simple_agentic_rag_api import AgenticRAGPipeline from raglight.config.agentic_rag_config import AgenticRAGConfig from raglight.config.vector_store_config import VectorStoreConfig from raglight.config.settings import Settings from raglight.models.data_source_model import FolderSource Settings.setup_logging() knowledge_base = [ FolderSource(path="./data"), ] vector_store_config = VectorStoreConfig( embedding_model=Settings.DEFAULT_EMBEDDINGS_MODEL, provider=Settings.HUGGINGFACE, database=Settings.CHROMA, persist_directory="./defaultDb", collection_name=Settings.DEFAULT_COLLECTION_NAME, ) config = AgenticRAGConfig( provider=Settings.MISTRAL, model="mistral-large-2411", k=10, max_steps=4, system_prompt=Settings.DEFAULT_AGENT_PROMPT, knowledge_base=knowledge_base, ) pipeline = AgenticRAGPipeline(config, vector_store_config) pipeline.build() response = pipeline.generate( "Explain how Agentic RAG differs from standard RAG" ) print(response) ``` -------------------------------- ### ChromaDB Vector Store Configuration (Python) Source: https://raglight.mintlify.app/documentation/vector-stores Shows how to configure ChromaDB for RAGLight, specifying the database, persistence directory, collection name, and search type. This configuration is crucial for defining retrieval strategies like semantic, BM25, or hybrid search. ```python vector_store_config = VectorStoreConfig( database=Settings.CHROMA, persist_directory="./defaultDb", collection_name="default", search_type=Settings.SEARCH_HYBRID, # or SEARCH_SEMANTIC, SEARCH_BM25 ) ``` -------------------------------- ### Vector Store Document Retrieval in RAG Pipeline (Python) Source: https://raglight.mintlify.app/documentation/vector-stores Demonstrates how a RAG pipeline retrieves relevant documents from a vector store using a similarity search. This is a core step where a query is used to find documents, which are then passed to the LLM. ```python retrieved_docs = vector_store.similarity_search(question, k=self.k) ``` -------------------------------- ### Initialize Logging in RAGLight Source: https://raglight.mintlify.app/documentation/settings Sets up the logging system for RAGLight, ensuring proper formatting of internal logs such as ingestion progress and retrieval statistics. This should be called once at the beginning of your script. ```python from raglight.config.settings import Settings # Call this once at the start of your script to enable structured logging Settings.setup_logging() ``` -------------------------------- ### Ingest Documents into RAGLight API Source: https://raglight.mintlify.app/documentation/rest-api This section covers the `/ingest` endpoint for indexing documents into the vector store. It supports multiple data sources including local folders, specific file paths, and GitHub repositories, which can be combined in a single request. All fields are optional, but at least one must be provided. ```bash curl -X POST http://localhost:8000/ingest \ -H "Content-Type: application/json" \ -d '{"data_path": "./docs"}' ``` ```bash curl -X POST http://localhost:8000/ingest \ -H "Content-Type: application/json" \ -d '{"file_paths": ["/data/report.pdf", "/data/notes.txt"]}' ``` ```bash curl -X POST http://localhost:8000/ingest \ -H "Content-Type: application/json" \ -d '{"github_url": "https://github.com/Bessouat40/RAGLight", "github_branch": "main"}' ``` -------------------------------- ### Set OpenAI API Key Source: https://raglight.mintlify.app/documentation/embeddings Environment variable configuration for the OpenAI API key. ```bash export OPENAI_API_KEY=your_key ``` -------------------------------- ### List ChromaDB Collections with RAGLight API Source: https://raglight.mintlify.app/documentation/rest-api This command demonstrates how to retrieve a list of available ChromaDB collections using the `/collections` endpoint. The response is a JSON object containing a 'collections' key with an array of collection names. ```bash curl http://localhost:8000/collections ``` -------------------------------- ### Direct LLM Usage with Mistral API (Python) Source: https://raglight.mintlify.app/documentation/llm-providers Illustrates the direct usage of the Mistral LLM provider via the Builder pattern, suitable for testing. It requires the `dotenv` library to load the MISTRAL_API_KEY and the 'raglight' package. ```python from raglight.rag.builder import Builder from raglight.config.settings import Settings from dotenv import load_dotenv load_dotenv() # Load MISTRAL_API_KEY Settings.setup_logging() llm = ( Builder() .with_llm( provider=Settings.MISTRAL, model_name="mistral-large-latest", api_key=Settings.MISTRAL_API_KEY, # Or set via env var system_prompt=Settings.DEFAULT_SYSTEM_PROMPT ) .build_llm() ) print(llm.generate({"question": "Summarize RAG architecture."}) ``` -------------------------------- ### Configure Hybrid Search with Builder API Source: https://raglight.mintlify.app/documentation/hybrid-search This code illustrates configuring hybrid search using RAGLight's Builder API. It chains methods to set up embeddings, the vector store with `search_type=Settings.SEARCH_HYBRID`, and the language model. The `build_rag` method finalizes the RAG pipeline configuration. ```python from raglight.rag.builder import Builder from raglight.config.settings import Settings rag = ( Builder() .with_embeddings( Settings.HUGGINGFACE, model_name=Settings.DEFAULT_EMBEDDINGS_MODEL, ) .with_vector_store( Settings.CHROMA, persist_directory="./defaultDb", collection_name=Settings.DEFAULT_COLLECTION_NAME, search_type=Settings.SEARCH_HYBRID, ) .with_llm(Settings.OLLAMA, model_name=Settings.DEFAULT_LLM) .build_rag(k=5) ) ``` -------------------------------- ### Print RAGLight Default System Prompts Source: https://raglight.mintlify.app/documentation/settings Prints the default system prompts used by RAGLight pipelines. This includes the standard RAG prompt and the agentic RAG prompt, which contains rules for tool use and reasoning. These prompts are designed to be readable and inspectable. ```python # Standard RAG prompt print(Settings.DEFAULT_SYSTEM_PROMPT) # Agentic RAG prompt (Tool use & reasoning rules) print(Settings.DEFAULT_AGENT_PROMPT) ``` -------------------------------- ### Configure Hybrid Search with VectorStoreConfig Source: https://raglight.mintlify.app/documentation/hybrid-search This snippet demonstrates how to configure hybrid search using the `VectorStoreConfig` class. It specifies the embedding model, provider, database, persistence directory, collection name, and importantly, sets the `search_type` to `Settings.SEARCH_HYBRID`. This configuration is then passed to `RAGPipeline` or `AgenticRAGPipeline`. ```python from raglight.config.vector_store_config import VectorStoreConfig from raglight.config.settings import Settings vector_store_config = VectorStoreConfig( embedding_model=Settings.DEFAULT_EMBEDDINGS_MODEL, provider=Settings.HUGGINGFACE, database=Settings.CHROMA, persist_directory="./defaultDb", collection_name=Settings.DEFAULT_COLLECTION_NAME, search_type=Settings.SEARCH_HYBRID, # "semantic" | "bm25" | "hybrid" ) ``` -------------------------------- ### Build a RAG Pipeline Step-by-Step with RAGLight Builder API (Python) Source: https://raglight.mintlify.app/documentation/rag Illustrates the use of RAGLight's Builder API for constructing a RAG pipeline with fine-grained control. This approach allows explicit configuration of embeddings, vector store, and LLM components before building the RAG graph. It's ideal for custom ingestion workflows and advanced experimentation. ```python from raglight.rag.builder import Builder from raglight.config.settings import Settings builder = Builder() rag = ( builder .with_embeddings( Settings.HUGGINGFACE, model_name=Settings.DEFAULT_EMBEDDINGS_MODEL, ) .with_vector_store( Settings.CHROMA, persist_directory="./defaultDb", collection_name=Settings.DEFAULT_COLLECTION_NAME, ) .with_llm( Settings.OLLAMA, model_name=Settings.DEFAULT_LLM, system_prompt=Settings.DEFAULT_SYSTEM_PROMPT, ) .build_rag(k=5) ) ``` -------------------------------- ### Configure Agentic RAG k Parameter Source: https://raglight.mintlify.app/documentation/agentic-rag Shows how to set the `k` parameter in AgenticRAGConfig. This defines the number of documents to be retrieved from the vector store at each retrieval step performed by the agent. ```python k=10 ``` -------------------------------- ### Configure Agentic RAG num_ctx Parameter Source: https://raglight.mintlify.app/documentation/agentic-rag Demonstrates setting the `num_ctx` parameter for the LLM context window size in AgenticRAGConfig. This is useful for accommodating larger retrieved chunks or longer reasoning chains. ```python num_ctx=8192 ``` -------------------------------- ### Configure Agentic RAG with MCP Server (Python) Source: https://raglight.mintlify.app/examples/agentic This Python snippet demonstrates how to configure an Agentic RAG pipeline to connect to a local MCP server. It sets up vector store configuration, defines the MCP server URL, and initializes the AgenticRAGPipeline with these settings. The agent can then access both local documents and external tools provided by the MCP server. ```python from raglight.rag.simple_agentic_rag_api import AgenticRAGPipeline from raglight.config.agentic_rag_config import AgenticRAGConfig from raglight.config.vector_store_config import VectorStoreConfig from raglight.config.settings import Settings from raglight.models.data_source_model import FolderSource Settings.setup_logging() # 1. Vector store configuration vector_store_config = VectorStoreConfig( embedding_model=Settings.DEFAULT_EMBEDDINGS_MODEL, provider=Settings.HUGGINGFACE, database=Settings.CHROMA, persist_directory="./defaultDb", collection_name=Settings.DEFAULT_COLLECTION_NAME, ) # 2. MCP server connection (SSE transport) mcp_servers = [ {"url": "http://127.0.0.1:8001/sse"} ] # 3. Configure Agentic RAG with MCP tools config = AgenticRAGConfig( provider=Settings.OPENAI, model="gpt-4o", k=10, max_steps=4, mcp_config=mcp_servers, knowledge_base=[FolderSource(path="./company_data")], ) # 4. Build and run agent = AgenticRAGPipeline(config, vector_store_config) agent.build() # The agent now has access to both your documents AND the MCP tools response = agent.generate( "Check the database for user 'Alice' and summarize her recent support tickets from the docs." ) print(response) ``` -------------------------------- ### Perform Standard Similarity Search Source: https://raglight.mintlify.app/documentation/vector-stores This code snippet demonstrates how to perform a standard similarity search using the vector store. It takes a query string and an integer `k` to specify the number of results to retrieve. This is the primary method for RAG queries. ```python docs = vector_store.similarity_search(question, k=5) ``` -------------------------------- ### Generate Answer with RAGLight API Source: https://raglight.mintlify.app/documentation/rest-api This snippet demonstrates how to ask a question to the RAG pipeline using the `/generate` endpoint. It requires a JSON request body containing the 'question' field and returns a JSON response with the 'answer'. ```bash curl -X POST http://localhost:8000/generate \ -H "Content-Type: application/json" \ -d '{"question": "What is RAGLight?"}' ``` -------------------------------- ### Configure Google Gemini Hosted Embeddings with Python Source: https://raglight.mintlify.app/documentation/embeddings Sets up RAGLight to use Google Gemini for hosted embeddings. Requires setting the GEMINI_API_KEY environment variable. ```python from raglight.config.vector_store_config import VectorStoreConfig from raglight.config.settings import Settings vector_store_config = VectorStoreConfig( embedding_model=Settings.GEMINI_EMBEDDING_MODEL, provider=Settings.GOOGLE_GEMINI, database=Settings.CHROMA, persist_directory="./defaultDb", collection_name=Settings.DEFAULT_COLLECTION_NAME, ) ``` -------------------------------- ### Query a RAG Pipeline in RAGLight (Python) Source: https://raglight.mintlify.app/documentation/rag Shows how to query an already built RAG pipeline to generate answers based on user questions. This process involves embedding the query, retrieving relevant documents from the vector store, constructing a prompt, and using an LLM for generation. This snippet is typically used after the pipeline has been built. ```python response = pipeline.generate("Explain how RAG works") ``` -------------------------------- ### POST /ingest/upload Source: https://raglight.mintlify.app/documentation/rest-api Upload files directly from the client using multipart/form-data for ingestion. Ideal when the server and files are on different machines. ```APIDOC ## POST /ingest/upload ### Description Upload files directly from the client via `multipart/form-data`. Use this when the server and the files are on **different machines**. ### Method POST ### Endpoint /ingest/upload ### Parameters #### Request Body - **files** (file) - Required - The file(s) to upload. Multiple files can be sent in a single request by using the same field name for each file. ### Request Example ```bash curl -X POST http://localhost:8000/ingest/upload \ -F "files=@./report.pdf" \ -F "files=@./notes.txt" ``` ### Response #### Success Response (200) - **message** (string) - A confirmation message indicating the number of files ingested and their names. #### Response Example ```json { "message": "Ingested 2 file(s): report.pdf, notes.txt" } ``` *Note: Uploaded files are processed and indexed, then deleted. Nothing is stored permanently on disk besides the embeddings.* ``` -------------------------------- ### Perform Class-Based Similarity Search Source: https://raglight.mintlify.app/documentation/vector-stores This code snippet shows how to perform a class-based similarity search. This specialized search is useful when dealing with codebases or structured symbols, allowing for retrieval of class or signature documents. It also takes a query string and `k` for the number of results. ```python docs = vector_store.similarity_search_class(question, k=5) ``` -------------------------------- ### RAGLight Default Retrieval Configuration Source: https://raglight.mintlify.app/documentation/settings Shows the default settings for retrieval operations in RAGLight, including the number of chunks to retrieve, the default collection name, and the default persistence directory for the vector store. ```python # Number of chunks to retrieve per query Settings.DEFAULT_K = 5 # Default Vector Store Collection Name Settings.DEFAULT_COLLECTION_NAME # Default Persist Directory Settings.DEFAULT_PERSIST_DIRECTORY ``` -------------------------------- ### Configure Agentic RAG max_steps Parameter Source: https://raglight.mintlify.app/documentation/agentic-rag Illustrates setting the `max_steps` parameter within AgenticRAGConfig. This parameter controls the maximum number of reasoning and retrieval iterations the agent can perform during its execution. ```python max_steps=4 ``` -------------------------------- ### Define FolderSource for Local Files Source: https://raglight.mintlify.app/documentation/knowledge Defines the FolderSource model, which represents a directory on the local filesystem. It includes a 'type' field set to 'folder' and a 'path' field for the directory's location. This source ingests all supported files within the specified directory recursively. ```python from pydantic import BaseModel from typing import Literal class FolderSource(BaseModel): type: Literal["folder"] = "folder" path: str ``` -------------------------------- ### Define GitHubSource for Remote Repositories Source: https://raglight.mintlify.app/documentation/knowledge Defines the GitHubSource model for representing remote GitHub repositories. It includes 'type' set to 'github', a 'url' for the repository, and an optional 'branch' field defaulting to 'main'. RAGLight fetches and checks out the specified branch to expose its files. ```python from pydantic import BaseModel, Field from typing import Literal class GitHubSource(BaseModel): type: Literal["github"] = "github" url: str branch: str = Field(default="main") ``` -------------------------------- ### Configure HuggingFace Local Embeddings with Python Source: https://raglight.mintlify.app/documentation/embeddings Configures local embeddings using a specific HuggingFace model ('all-MiniLM-L6-v2') with the Chroma database. This is suitable for local-first RAG applications. ```python from raglight.config.vector_store_config import VectorStoreConfig from raglight.config.settings import Settings vector_store_config = VectorStoreConfig( embedding_model="all-MiniLM-L6-v2", provider=Settings.HUGGINGFACE, database=Settings.CHROMA, persist_directory="./defaultDb", collection_name=Settings.DEFAULT_COLLECTION_NAME, ) ``` -------------------------------- ### Manually Ingest Documents with RAGLight Builder API (Python) Source: https://raglight.mintlify.app/documentation/rag Demonstrates the explicit document ingestion process when using the RAGLight Builder API. This method provides control over when ingestion occurs, allows for reusing vector stores across pipelines, and facilitates debugging of indexing issues. The `ingest` method is called on the configured vector store. ```python rag.vector_store.ingest(data_path="./data") ``` -------------------------------- ### Access Default Agent System Prompt Source: https://raglight.mintlify.app/documentation/agentic-rag Provides the code to access the default system prompt used by the agent in RAGLight. This prompt defines the agent's reasoning structure, tool usage rules, and retrieval invocation logic. ```python Settings.DEFAULT_AGENT_PROMPT ```