### Setup and Run RAG Application with Python Virtual Environment Source: https://context7.com/neuml/rag/llms.txt Instructions for setting up a Python virtual environment, installing dependencies, and running the Streamlit application directly. ```bash # Create and activate virtual environment python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate # Install requirements pip install -r requirements.txt # Start the Streamlit application streamlit run rag.py # The application will be available at http://localhost:8501 ``` -------------------------------- ### Start RAG Application with Streamlit Source: https://github.com/neuml/rag/blob/master/README.md Start the RAG Streamlit application after installing dependencies. This command launches the interactive web interface. ```bash streamlit run rag.py ``` -------------------------------- ### Graph RAG Query Examples Source: https://context7.com/neuml/rag/llms.txt Examples of queries for Graph RAG, demonstrating graph query expansion with 'gq:', graph path traversal with '->', and combined query patterns. ```text # Graph query expansion (gq: prefix) - starts with vector search, expands via graph gq: Tell me about Linux # Graph path query - finds nodes matching concepts and traverses paths between them linux -> macos -> microsoft windows # Combined query - graph path with graph RAG query linux -> macos -> microsoft windows gq: Tell me about Linux # The application displays a visual graph showing relationships between nodes ``` -------------------------------- ### Install RAG Dependencies Source: https://github.com/neuml/rag/blob/master/README.md Install the required Python packages for the RAG application using pip. It is recommended to run this within a Python virtual environment. ```bash pip install -r requirements.txt ``` -------------------------------- ### Graph RAG Combined Query Example Source: https://github.com/neuml/rag/blob/master/README.md Example combining graph path query and graph query expansion. It first traverses a path and then performs a graph query within that path's context. ```text linux -> macos -> microsoft windows gq: Tell me about Linux ``` -------------------------------- ### Vector RAG Query Example Source: https://github.com/neuml/rag/blob/master/README.md Example of a vector RAG query to find relevant documents and generate an answer using an LLM. The query 'Who created Linux?' triggers a vector search. ```text Who created Linux? ``` -------------------------------- ### Configure RAG Application with Environment Variables Source: https://context7.com/neuml/rag/llms.txt Example of setting multiple environment variables to customize the RAG application's title, LLM, embeddings, context size, and persistence. ```bash # Example: Configure multiple environment variables export TITLE="My Custom RAG App" export LLM="Qwen/Qwen3-4B-Instruct-2507" export EMBEDDINGS="neuml/txtai-wikipedia-slim" export CONTEXT=15 export MAXLENGTH=4096 export PERSIST=/path/to/save/index streamlit run rag.py ``` -------------------------------- ### Graph RAG Path Query Example Source: https://github.com/neuml/rag/blob/master/README.md Example of a Graph RAG path query. This query finds nodes related to the provided concepts and traverses a graph path to build context for the LLM. ```text linux -> macos -> microsoft windows ``` -------------------------------- ### Graph RAG Query with Expansion Source: https://github.com/neuml/rag/blob/master/README.md Example of a Graph RAG query using the 'gq:' prefix for graph query expansion. This starts with a vector search and expands results using a graph network. ```text gq: Tell me about Linux ``` -------------------------------- ### Vector RAG Query Examples Source: https://context7.com/neuml/rag/llms.txt Examples of natural language questions to input into the chat interface for standard Vector RAG queries. The application uses vector search to find relevant context and generate answers. ```text # Standard Vector RAG query examples (type in chat input) Who created Linux? # Returns: Answer based on vector search results about Linux creators What is machine learning? # Returns: Answer using semantically similar content about ML Explain quantum computing # Returns: Generated response with context from relevant documents ``` -------------------------------- ### Run RAG Application with Docker Source: https://github.com/neuml/rag/blob/master/README.md Run the RAG application using Docker with default settings. Ensure Docker is installed and the image is pulled. ```bash docker run -d --gpus=all -it -p 8501:8501 neuml/rag ``` -------------------------------- ### Run RAG with GPT-OSS LLM Source: https://github.com/neuml/rag/blob/master/README.md Use this command to run the RAG application with the GPT-OSS LLM. Ensure Docker is installed and the neuml/rag image is available. ```bash docker run -d --gpus=all -it -p 8501:8501 -e LLM=openai/gpt-oss-20b neuml/rag ``` -------------------------------- ### Run RAG with a different embeddings index Source: https://github.com/neuml/rag/blob/master/README.md Specify a custom embeddings index using the EMBEDDINGS environment variable. This example uses 'neuml/arxiv'. ```bash docker run -d --gpus=all -it -p 8501:8501 -e EMBEDDINGS=neuml/arxiv neuml/rag ``` -------------------------------- ### Run RAG with an empty embeddings index Source: https://github.com/neuml/rag/blob/master/README.md Start the RAG application with an empty embeddings index by setting EMBEDDINGS to an empty string. This will build a new index. ```bash docker run -d --gpus=all -it -p 8501:8501 -e EMBEDDINGS= neuml/rag ``` -------------------------------- ### Add Text String to Index Source: https://github.com/neuml/rag/blob/master/README.md Example of adding a text string directly to the index. This creates a new entry in the Embeddings database. ```text # txtai is an all-in-one AI framework ``` -------------------------------- ### Run RAG Application with Custom Embeddings via Docker Source: https://context7.com/neuml/rag/llms.txt Specify a different embeddings index from HuggingFace or start with an empty index when running the RAG application via Docker. ```bash # Run with a different embeddings index from HuggingFace docker run -d --gpus=all -it -p 8501:8501 -e EMBEDDINGS=neuml/arxiv neuml/rag ``` ```bash # Start with an empty embeddings index docker run -d --gpus=all -it -p 8501:8501 -e EMBEDDINGS= neuml/rag ``` -------------------------------- ### View Application Settings Source: https://context7.com/neuml/rag/llms.txt Displays current application configuration and index statistics using the ':settings' command in the chat input. The output is presented as a markdown table. ```bash # Type in chat input to view settings :settings ``` -------------------------------- ### Viewing Application Settings Source: https://context7.com/neuml/rag/llms.txt Instructions on how to view current application configuration and index statistics using the ':settings' command. ```bash # Type in chat input to view settings :settings # Returns a table with current settings: # |Name|Value| # |----|-----| # |RECORD COUNT|12500| # |EMBEDDINGS|neuml/txtai-wikipedia-slim| # |DATA|None| # |PERSIST|None| ``` -------------------------------- ### Run RAG with GPT-5.1 LLM and API Key Source: https://github.com/neuml/rag/blob/master/README.md Launch the RAG application with the GPT-5.1 LLM, providing your OpenAI API key as an environment variable. ```bash docker run -d --gpus=all -it -p 8501:8501 -e LLM=gpt-5.1 -e OPENAI_API_KEY=your-api-key neuml/rag ``` -------------------------------- ### Building and Indexing Data with Docker Source: https://context7.com/neuml/rag/llms.txt Instructions for building embeddings index from local directories using Docker, persisting embeddings and cache, and using Docling for text extraction. ```bash # Build embeddings index from a local directory of files docker run -d --gpus=all -it -p 8501:8501 \ -e DATA=/data/path \ -v /local/path:/data/path \ neuml/rag # Persist embeddings and cache models for reuse docker run -d --gpus=all -it -p 8501:8501 \ -e DATA=/data/path \ -e EMBEDDINGS=/data/embeddings \ -e PERSIST=/data/embeddings \ -e HF_HOME=/data/modelcache \ -v /localdata:/data \ neuml/rag # Use Docling text extraction backend for better document parsing docker run -d --gpus=all -it -p 8501:8501 \ -e TEXTBACKEND=docling \ neuml/rag ``` -------------------------------- ### Application Class Initialization Source: https://context7.com/neuml/rag/llms.txt Initializes the RAG pipeline, embeddings, and LLM. Loads embeddings from environment or creates a new index. Sets context size for RAG queries. ```python from txtai import Embeddings, LLM, RAG class Application: def __init__(self): # Load LLM from environment or default self.llm = LLM(os.environ.get("LLM", "Qwen/Qwen3-4B-Instruct-2507")) # Load or create embeddings index self.embeddings = self.load() # Set context size for RAG queries self.context = int(os.environ.get("CONTEXT", 10)) # Create RAG pipeline with template template = """ Answer the following question using only the context below. Only include information specifically discussed. question: {question} context: {context} """ self.rag = RAG( self.embeddings, self.llm, system="You are a friendly assistant. You answer questions from users.", template=template, context=self.context, ) ``` -------------------------------- ### Build embeddings index from local directory Source: https://github.com/neuml/rag/blob/master/README.md Index data from a local directory by mounting it into the container and setting the DATA environment variable. Ensure the volume mapping is correct. ```bash docker run -d --gpus=all -it -p 8501:8501 -e DATA=/data/path -v local/path:/data/path neuml/rag ``` -------------------------------- ### Use Docling Text Extraction Backend Source: https://context7.com/neuml/rag/llms.txt Configures the Docker container to use the Docling text extraction backend for improved document parsing. This is set via the TEXTBACKEND environment variable. ```bash docker run -d --gpus=all -it -p 8501:8501 \ -e TEXTBACKEND=docling \ neuml/rag ``` -------------------------------- ### Use Docling text extraction backend Source: https://github.com/neuml/rag/blob/master/README.md Configure the RAG application to use the 'docling' backend for text extraction by setting the TEXTBACKEND environment variable. ```bash docker run -d --gpus=all -it -p 8501:8501 -e TEXTBACKEND=docling neuml/rag ``` -------------------------------- ### Run RAG with GPT-OSS via Ollama Source: https://github.com/neuml/rag/blob/master/README.md Configure the RAG application to use GPT-OSS through Ollama. This requires Ollama to be running and accessible via host.docker.internal. ```bash docker run -d --gpus=all -it -p 8501:8501 --add-host=host.docker.internal:host-gateway \ -e LLM=ollama/gpt-oss -e OLLAMA_API_BASE=http://host.docker.internal:11434 \ neuml/rag ``` -------------------------------- ### Run RAG Application with Ollama Backend via Docker Source: https://context7.com/neuml/rag/llms.txt Configure the RAG application to use Ollama as the LLM backend. This requires exposing the Ollama API to the Docker container. ```bash # Run with Ollama backend docker run -d --gpus=all -it -p 8501:8501 --add-host=host.docker.internal:host-gateway \ -e LLM=ollama/gpt-oss -e OLLAMA_API_BASE=http://host.docker.internal:11434 \ neuml/rag ``` -------------------------------- ### Build Embeddings Index from Local Directory Source: https://context7.com/neuml/rag/llms.txt Builds an embeddings index from a local directory of files using Docker. Mounts the local directory to the container and exposes port 8501. ```bash docker run -d --gpus=all -it -p 8501:8501 \ -e DATA=/data/path \ -v /local/path:/data/path \ neuml/rag ``` -------------------------------- ### Initialize and Call GraphContext Source: https://context7.com/neuml/rag/llms.txt Initializes the GraphContext with embeddings and context size. The call method processes a question, returning graph context if it's a graph query, otherwise returning the question with no context. ```python class GraphContext: def __init__(self, embeddings, context): """Initialize with embeddings instance and context size.""" self.embeddings = embeddings self.context = context def __call__(self, question): """ Process question and return (question, context) tuple. Returns graph context if question is a graph query, else returns (question, None). """ query, concepts, context = self.parse(question) if self.embeddings.graph and (query or concepts): # Generate graph path query path = self.path(query, concepts) # Execute graph search and build context graph = self.embeddings.graph.search(path, graph=True) if graph.count(): context = [ {"id": graph.attribute(node, "id"), "text": graph.attribute(node, "text")} for node in list(graph.scan()) ] return question, context ``` -------------------------------- ### Programmatic Data Indexing - Extract Content Source: https://context7.com/neuml/rag/llms.txt Extracts sections from input files using the Textractor pipeline. Initializes Textractor if not already available, using the TEXTBACKEND environment variable if set. ```python def extract(self, inputs): """Extract sections using Textractor pipeline.""" if not self.textractor: self.textractor = Textractor( paragraphs=True, backend=os.environ.get("TEXTBACKEND", "available"), ) return self.textractor(inputs) ``` -------------------------------- ### Programmatic Data Indexing - Infer Topics Source: https://context7.com/neuml/rag/llms.txt Generates LLM topics for graph nodes. It iterates through graph nodes, and if a node lacks a topic, it extracts text, generates a topic using an LLM, and adds it as an attribute. ```python def infertopics(self, embeddings, start): """Generate LLM topics for graph nodes.""" prompt = """ Create a simple, concise topic for the following text. Only return the topic name. Text: {text} """ if embeddings.graph: for uid in embeddings.graph.scan(): rid = embeddings.graph.attribute(uid, "id") topic = embeddings.graph.attribute(uid, "topic") if AutoId.valid(rid) and not topic: text = embeddings.graph.attribute(uid, "text") # Generate topic with LLM and set on graph node topic = self.llm([[{"role": "user", "content": prompt.format(text=text)}]]) embeddings.graph.addattribute(uid, "topic", topic) ``` -------------------------------- ### Persist embeddings and cache models Source: https://github.com/neuml/rag/blob/master/README.md Persist embeddings and cache models by specifying directories for DATA, EMBEDDINGS, and HF_HOME, and mounting a volume for persistent storage. ```bash docker run -d --gpus=all -it -p 8501:8501 -e DATA=/data/path -e EMBEDDINGS=/data/embeddings \ -e PERSIST=/data/embeddings -e HF_HOME=/data/modelcache -v localdata:/data neuml/rag ``` -------------------------------- ### Run RAG Application with Custom LLM via Docker Source: https://context7.com/neuml/rag/llms.txt Run the RAG application with a custom LLM model specified via the LLM environment variable. This allows using different language models for generation. ```bash # Run with a custom LLM model docker run -d --gpus=all -it -p 8501:8501 -e LLM=openai/gpt-oss-20b neuml/rag ``` ```bash # Run with OpenAI GPT-5.1 docker run -d --gpus=all -it -p 8501:8501 -e LLM=gpt-5.1 -e OPENAI_API_KEY=your-api-key neuml/rag ``` -------------------------------- ### Add File or URL to Index Source: https://github.com/neuml/rag/blob/master/README.md Method to add data to the RAG index by specifying a file path or URL. The RAG application reads the content and loads it into the index. ```text # file path or URL ``` -------------------------------- ### Load Embeddings Source: https://context7.com/neuml/rag/llms.txt Loads embeddings from a specified path, HuggingFace Hub, or creates a new index if none exists. Supports loading from cloud providers. ```python def load(self): """Load embeddings from path, HuggingFace Hub, or create new index.""" embeddings = Embeddings() database = os.environ.get("EMBEDDINGS", "neuml/txtai-wikipedia-slim") if embeddings.exists(database): embeddings.load(database) elif embeddings.exists(cloud={"provider": "huggingface-hub", "container": database}): embeddings.load(provider="huggingface-hub", container=database) else: embeddings = self.create() return embeddings ``` -------------------------------- ### Application Class API Source: https://context7.com/neuml/rag/llms.txt The main Application class manages the RAG pipeline, embeddings, and user interactions. ```APIDOC ## Application Class API The main Application class manages the RAG pipeline, embeddings, and user interactions. ### Class: `Application` #### `__init__(self)` Initializes the Application class. Loads the LLM, embeddings index, and sets up the RAG pipeline. * **LLM Loading:** Loads LLM from environment variable `LLM` or defaults to `Qwen/Qwen3-4B-Instruct-2507`. * **Embeddings Loading:** Loads embeddings using the `load()` method. Defaults to `neuml/txtai-wikipedia-slim` from environment variable `EMBEDDINGS`. * **Context Size:** Sets context size for RAG queries from environment variable `CONTEXT` (defaults to 10). * **RAG Pipeline Setup:** Creates a RAG pipeline with a specified template, system prompt, and context size. #### `load(self)` Loads embeddings from a path, HuggingFace Hub, or creates a new index if none exists. * **Default Path:** Checks for embeddings at `neuml/txtai-wikipedia-slim`. * **HuggingFace Hub:** Checks for embeddings on HuggingFace Hub using the `EMBEDDINGS` environment variable. * **New Index Creation:** If no existing index is found, it calls the `create()` method. #### `create(self)` Creates a new, empty embeddings index with graph support. * **`autoid`:** Set to `uuid5`. * **`path`:** Set to `intfloat/e5-large`. * **`instructions`:** Configured for query and data passages. * **`content`:** Set to `True`. * **`graph`:** Enabled with `approximate=False` and `minscore=0.7`. ``` -------------------------------- ### Programmatic Data Indexing Source: https://context7.com/neuml/rag/llms.txt Python methods for streaming data, extracting sections using Textractor, and inferring topics for graph nodes. ```python def stream(self, data): """Stream extracted content from a data directory.""" for sections in self.extract(glob(f"{data}/**/*", recursive=True)): yield from sections def extract(self, inputs): """Extract sections using Textractor pipeline.""" if not self.textractor: self.textractor = Textractor( paragraphs=True, backend=os.environ.get("TEXTBACKEND", "available"), ) return self.textractor(inputs) def infertopics(self, embeddings, start): """Generate LLM topics for graph nodes.""" prompt = """ Create a simple, concise topic for the following text. Only return the topic name. Text: {text} """ if embeddings.graph: for uid in embeddings.graph.scan(): rid = embeddings.graph.attribute(uid, "id") topic = embeddings.graph.attribute(uid, "topic") if AutoId.valid(rid) and not topic: text = embeddings.graph.attribute(uid, "text") # Generate topic with LLM and set on graph node topic = self.llm([[{"role": "user", "content": prompt.format(text=text)}]]) embeddings.graph.addattribute(uid, "topic", topic) ``` -------------------------------- ### Add Data to Index Source: https://context7.com/neuml/rag/llms.txt Use the '#' prefix to upload files, URLs, or text content to the embeddings index. Data can be added dynamically to a running application. ```bash # https://example.com/document.pdf ``` ```bash # /path/to/local/document.txt ``` ```bash # txtai is an all-in-one AI framework for semantic search ``` ```bash # This is my custom note about machine learning concepts ``` -------------------------------- ### Persist Embeddings and Cache Models Source: https://context7.com/neuml/rag/llms.txt Persists embeddings and caches models for reuse by specifying directories for data, embeddings, persistence, and Hugging Face cache. This allows for faster subsequent runs. ```bash docker run -d --gpus=all -it -p 8501:8501 \ -e DATA=/data/path \ -e EMBEDDINGS=/data/embeddings \ -e PERSIST=/data/embeddings \ -e HF_HOME=/data/modelcache \ -v /localdata:/data \ neuml/rag ``` -------------------------------- ### Create Embeddings Index Source: https://context7.com/neuml/rag/llms.txt Creates a new, empty embeddings index with graph support. Configures autoid, path, instructions for query/data, content inclusion, and graph parameters. ```python def create(self): """Create a new empty embeddings index with graph support.""" return Embeddings( autoid="uuid5", path="intfloat/e5-large", instructions={"query": "query: ", "data": "passage: "}, content=True, graph={"approximate": False, "minscore": 0.7}, ) ``` -------------------------------- ### Parse Question for Graph Query Patterns Source: https://context7.com/neuml/rag/llms.txt Parses a question to identify graph query patterns, specifically looking for a 'gq: ' prefix or '->' separator to extract query components and concepts. ```python def parse(self, question): """ Parse question for graph query patterns. - 'gq: ' prefix for graph query expansion - '->' separator for concept path queries """ prefix = "gq: " query, concepts, context = None, None, None if "->" in question or question.strip().lower().startswith(prefix): concepts = [x.strip() for x in question.strip().lower().split("->")] if prefix in concepts[-1]: query, concepts = concepts[-1], concepts[:-1] query = [x.strip() for x in query.split(prefix, 1)] if query[0]: concepts.append(query[0]) if len(query) > 1: query = query[1] return query, concepts, context ``` -------------------------------- ### Generate Cypher MATCH PATH Query Source: https://context7.com/neuml/rag/llms.txt Generates a Cypher MATCH PATH query based on provided concepts or a question. It searches for embeddings and constructs a path query with a specified limit. ```python def path(self, question, concepts): """ Generate Cypher MATCH PATH query from concepts or question. Returns query like: MATCH P=(id1)-[*1..4]->(id2)-[*1..4]->(id3) RETURN P LIMIT 10 """ ids = [] if concepts: for concept in concepts: uid = self.embeddings.search(concept, 1)[0]["id"] ids.append(f'({{id: "{uid}"}})') else: for x in self.embeddings.search(question, 3): ids.append(f'({{id: "{x["id"]}"}})') ids = "-[*1..4]->".join(ids) return f"MATCH P={ids} RETURN P LIMIT {self.context}" ``` -------------------------------- ### Programmatic Data Indexing - Stream Content Source: https://context7.com/neuml/rag/llms.txt Streams extracted content from a data directory. It iterates through files, extracts sections using the Textractor pipeline, and yields them. ```python def stream(self, data): """Stream extracted content from a data directory.""" for sections in self.extract(glob(f"{data}/**/*", recursive=True)): yield from sections ``` -------------------------------- ### GraphContext Class API Source: https://context7.com/neuml/rag/llms.txt The GraphContext class handles graph-based context generation for Graph RAG queries. It processes questions to return relevant graph context. ```APIDOC ## GraphContext Class API The GraphContext class handles graph-based context generation for Graph RAG queries. ### `__init__` Initialize with embeddings instance and context size. ### `__call__` Process question and return (question, context) tuple. Returns graph context if question is a graph query, else returns (question, None). ### `parse` Parse question for graph query patterns. - 'gq: ' prefix for graph query expansion - '->' separator for concept path queries ### `path` Generate Cypher MATCH PATH query from concepts or question. Returns query like: MATCH P=(id1)-[*1..4]->(id2)-[*1..4]->(id3) RETURN P LIMIT 10 ``` -------------------------------- ### Adding Data to the Index Source: https://context7.com/neuml/rag/llms.txt Upload files, URLs, or text content to the embeddings index using the '#' prefix. Data can be added dynamically to the running application. ```APIDOC ## Adding Data to the Index Upload files, URLs, or text content to the embeddings index using the `#` prefix. Data can be added dynamically to the running application. When a query begins with `#`, the application reads the URL/file or stores the text directly in the embeddings index. ### Examples * **Upload from URL:** ``` # https://example.com/document.pdf ``` * **Upload from local file path:** ``` # /path/to/local/document.txt ``` * **Add custom text directly to the index:** ``` # txtai is an all-in-one AI framework for semantic search ``` * **Add notes or content as text:** ``` # This is my custom note about machine learning concepts ``` ``` -------------------------------- ### Add Custom Text to Index Source: https://github.com/neuml/rag/blob/master/README.md Method to add custom text directly into the RAG index. The provided string is processed and added as a new entry to the Embeddings database. ```text # custom notes and text as a string here! ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.