{"id":17526844,"url":"https://github.com/neuml/rag","last_synced_at":"2025-03-06T06:30:55.875Z","repository":{"id":250249570,"uuid":"833809926","full_name":"neuml/rag","owner":"neuml","description":"🚀 Retrieval Augmented Generation (RAG) with txtai. Combine search and LLMs to find insights with your own data.","archived":false,"fork":false,"pushed_at":"2024-08-19T15:27:39.000Z","size":3282,"stargazers_count":203,"open_issues_count":0,"forks_count":10,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-08-20T17:30:31.280Z","etag":null,"topics":["large-language-models","llm","machine-learning","nlp","python","rag","retrieval-augmented-generation","search","txtai"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/neuml.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-25T19:49:54.000Z","updated_at":"2024-08-19T14:48:25.000Z","dependencies_parsed_at":"2024-07-26T04:45:57.837Z","dependency_job_id":"69721386-5c3b-4773-9701-ca9d7bfb2d07","html_url":"https://github.com/neuml/rag","commit_stats":null,"previous_names":["neuml/rag"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neuml%2Frag","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neuml%2Frag/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neuml%2Frag/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neuml%2Frag/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/neuml","download_url":"https://codeload.github.com/neuml/rag/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242161426,"owners_count":20081869,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["large-language-models","llm","machine-learning","nlp","python","rag","retrieval-augmented-generation","search","txtai"],"created_at":"2024-10-20T15:02:33.820Z","updated_at":"2025-03-06T06:30:55.863Z","avatar_url":"https://github.com/neuml.png","language":"Python","funding_links":[],"categories":["\u003cimg src=\"./assets/satellite.svg\" width=\"16\" height=\"16\" style=\"vertical-align: middle;\"\u003e Satellites","Python"],"sub_categories":[],"readme":"# 🚀 RAG with txtai\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://raw.githubusercontent.com/neuml/rag/master/images/overview.png\"/\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/neuml/rag/releases\"\u003e\n        \u003cimg src=\"https://img.shields.io/github/release/neuml/rag.svg?style=flat\u0026color=success\" alt=\"Version\"/\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/neuml/rag\"\u003e\n        \u003cimg src=\"https://img.shields.io/github/last-commit/neuml/rag.svg?style=flat\u0026color=blue\" alt=\"GitHub last commit\"/\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/neuml/rag/issues\"\u003e\n        \u003cimg src=\"https://img.shields.io/github/issues/neuml/rag.svg?style=flat\u0026color=success\" alt=\"GitHub issues\"/\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\nThis project is a Retrieval Augmented Generation (RAG) Streamlit application backed by [txtai](https://github.com/neuml/txtai). \n\nRetrieval Augmented Generation (RAG) helps generate factually correct content by limiting the context in which a LLM can generate answers. This is typically done with a search query that hydrates a prompt with a relevant context.\n\nThis application supports two categories of RAG.\n\n- Vector RAG: Context supplied via a vector search query\n- Graph RAG: Context supplied via a graph path traversal query\n\n## Quickstart\n\nThe two primary ways to run this application are as a Docker container and with a Python virtual environment. Running through Docker is recommended, at least to get an idea of the application's capabilities.\n\n### Docker\n\n[neuml/rag](https://hub.docker.com/r/neuml/rag) is available on Docker Hub: \n\nThis can be run with the default settings as follows.\n\n```\ndocker run -d --gpus=all -it -p 8501:8501 neuml/rag\n```\n\n### Python virtual environment\n\nThe application can also be directly installed and run. It's recommended that this be run within a Python virtual environment.\n\n```\npip install -r requirements.txt\n```\n\nStart the application.\n\n```\nstreamlit run rag.py\n```\n\n## Demo\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://raw.githubusercontent.com/neuml/rag/master/images/demo.gif\"/\u003e\n\u003c/p\u003e\n\nThe short video clip above gives a brief overview on this RAG system. It shows a basic vector RAG query. It also shows a Graph RAG query with uploaded data. The following sections cover more on these concepts.\n\n## RAG\n\n![Vector](https://raw.githubusercontent.com/neuml/rag/master/images/vector.png)\n\nTraditional RAG or vector RAG runs a vector search to find the top N most relevant matches to a user's input. Those matches are passed to an LLM and the answer is returned.\n\nThe query `Who created Linux?` runs a vector search for the best matching documents in the Embeddings index. Those matches are then placed into a LLM prompt. The LLM prompt is executed and the answer is returned.\n\n## Graph RAG\n\n![Graph](https://raw.githubusercontent.com/neuml/rag/master/images/graph.png)\n\nGraph RAG is a new method that uses knowledge or semantic graphs to generate a context. Instead of a vector search, graph path queries are run. Graph RAG in the context of this application supports the following methods to generate context.\n\n- Graph query with the `gq: ` prefix. This is a form of graph query expansion. It starts with a vector search to find the top n results. Those results are then expanded using a graph network stored alongside the vector database.\n  - `gq: Tell me about Linux`\n\n- Graph path query. This query takes a list of concepts and finds the nodes that match closest to those concepts. A graph path traversal then runs to build a context of nodes related to those concepts. The result of this traversal is passed to the LLM as the context.\n  - `linux -\u003e macos -\u003e microsoft windows`\n\n- Combination of both. This first runs a graph path query then runs a graph query only within the context of that path traversal.\n  - `linux -\u003e macos -\u003e microsoft windows gq: Tell me about Linux`\n\nEvery Graph RAG query response will also show a corresponding graph to help understand how the query works. Each node in the graph is a section (paragraph). The node nodes are generated with a LLM prompt that applies a topic label at upload time.\n\n## Adding data to the index\n\nRegardless of whether the RAG application was a new Embeddings index or an existing one, additional data can be added.\n\nData can be added as follows.\n\n| Method                                      |                                        |\n|:------------------------------------------- |:-------------------------------------- |\n| `# file path or URL`                        | ![Upload File](https://raw.githubusercontent.com/neuml/rag/master/images/upload-file.png) |\n| `# custom notes and text as a string here!` | ![Upload Text](https://raw.githubusercontent.com/neuml/rag/master/images/upload-text.png) |\n\nWhen a query begins with a `#` the URL or file is read by the RAG application and loaded into the index. This method also supports loading text directly into the index. For example `# txtai is an all-in-one embeddings database` would create a new entry in the Embeddings database. \n\n## Configuration parameters\n\nThe RAG application has a number of environment variables that can be set to control how the application behaves.\n\n| Variable    | Description                                 | Default Value                       |\n|:----------- |:------------------------------------------- |:----------------------------------- |\n| TITLE       | Main title of the application               | 🚀 RAG with txtai                   |\n| EXAMPLES    | List of queries separated by `;`            | `Who created Linux?`                |\n|             |                                             | `gq: Tell me about Linux`           |\n|             |                                             | `linux -\u003e macos -\u003e microsoft windows` |\n|             |                                             | `linux -\u003e macos -\u003e microsoft windows gq: Tell me about Linux` |\n| LLM         | Path to LLM                                 | x86-64: [Llama-3.1-8B-Instruct-AWQ-INT4](https://hf.co/hugging-quants/Meta-Llama-3.1-8B-Instruct-AWQ-INT4) |\n|             |                                             | arm64 : [Llama-3.1-8B-Instruct-GGUF](https://hf.co/bartowski/Meta-Llama-3.1-8B-Instruct-GGUF) |\n| EMBEDDINGS  | Embeddings database path                    | [neuml/txtai-wikipedia-slim](https://hf.co/NeuML/txtai-wikipedia-slim) |\n| MAXLENGTH   | Maximum generation length                   | 2048 for topics, 4096 for RAG       |\n| CONTEXT     | RAG context size                            | 10                                  |\n| TEXTBACKEND | [Text extraction backend](https://neuml.github.io/txtai/pipeline/data/filetohtml/#txtai.pipeline.FileToHTML.__init__)                     | available                         |\n| DATA        | Optional directory to index data from       | None                                |\n| PERSIST     | Optional directory to save index updates to | None                                |\n| TOPICSBATCH | Optional batch size for LLM topic queries   | None                                |\n\n*Note: AWQ models are only supported on `x86-64` machines*\n\nIn the application, these settings can be shown by typing `:settings`.\n\nSee the following examples for setting this configuration with the Docker container. When running within a Python virtual environment, simply set these as environment variables.\n\n### Llama 3.1 8B\n\n```\ndocker run -d --gpus=all -it -p 8501:8501 -e LLM=hugging-quants/Meta-Llama-3.1-8B-Instruct-AWQ-INT4 neuml/rag\n```\n\n### Llama 3.1 8B via Ollama\n\n```\ndocker run -d --gpus=all -it -p 8501:8501 --add-host=host.docker.internal:host-gateway \\\n-e LLM=ollama/llama3.1:8b-instruct-q4_K_M -e OLLAMA_API_BASE=http://host.docker.internal:11434 \\\nneuml/rag\n```\n\n### GPT-4o\n\n```\ndocker run -d --gpus=all -it -p 8501:8501 -e LLM=gpt-4o -e OPENAI_API_KEY=your-api-key neuml/rag\n```\n\n### Run with another embeddings index\n\n```\ndocker run -d --gpus=all -it -p 8501:8501 -e EMBEDDINGS=neuml/arxiv neuml/rag\n```\n\n### Start with an empty embeddings index\n\n```\ndocker run -d --gpus=all -it -p 8501:8501 -e EMBEDDINGS= neuml/rag\n```\n\n### Build an embeddings index with a local directory of files\n\n```\ndocker run -d --gpus=all -it -p 8501:8501 -e DATA=/data/path -v local/path:/data/path neuml/rag\n```\n\n### Use the Docling text extraction backend\n\n```\ndocker run -d --gpus=all -it -p 8501:8501 -e TEXTBACKEND=docling neuml/rag\n```\n\n### Persist embeddings and cache models\n\n```\ndocker run -d --gpus=all -it -p 8501:8501 -e DATA=/data/path -e EMBEDDINGS=/data/embeddings \\\n-e PERSIST=/data/embeddings -e HF_HOME=/data/modelcache -v localdata:/data neuml/rag\n```\n\nSee the documentation for the [LLM pipeline](https://neuml.github.io/txtai/pipeline/text/llm/) and [Embeddings](https://neuml.github.io/txtai/embeddings/) for more information.\n\n## Further Reading\n\n- [Introducing RAG with txtai](https://medium.com/neuml/introducing-rag-with-txtai-f3456977cf91)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneuml%2Frag","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fneuml%2Frag","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneuml%2Frag/lists"}