This document explains a critical consideration for running the RAG-Anything project in an environment with no internet access.
The RAGAnything core engine relies on the LightRAG library for its primary functionality. LightRAG, in turn, uses OpenAI's tiktoken library for text tokenization.
By default, the tiktoken library has a network dependency. On its first use, it attempts to download tokenizer models from OpenAI's public servers (openaipublic.blob.core.windows.net). If the application is running in an offline or network-restricted environment, this download will fail, causing the LightRAG instance to fail to initialize.
This results in an error similar to the following:
Failed to initialize LightRAG instance: HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/o200k_ba
This dependency is indirect. The RAG-Anything codebase itself does not directly import or call tiktoken. The call is made from within the lightrag library.
To resolve this issue and enable fully offline operation, you must provide a local cache for the tiktoken models. This is achieved by setting the TIKTOKEN_CACHE_DIR environment variable before the application starts.
When this environment variable is set, tiktoken will look for its model files in the specified local directory instead of attempting to download them from the internet.
-
Create a Model Cache: In an environment with internet access, run the provided script to download and cache the necessary
tiktokenmodels.# Run the cache creation script uv run scripts/create_tiktoken_cache.pyThis will create a
tiktoken_cachedirectory in your project root containing the required model files. -
Configure the Environment Variable: Add the following line to your
.envfile:TIKTOKEN_CACHE_DIR=./tiktoken_cache
Important: You should ensure that the
.envfile is loaded beforeLightRAGimportstiktoken, making this configuration effective.import os from typing import Dict, Any, Optional, Callable import sys import asyncio import atexit from dataclasses import dataclass, field from pathlib import Path from dotenv import load_dotenv # Add project root directory to Python path sys.path.insert(0, str(Path(__file__).parent.parent)) # Load environment variables FIRST - before any imports that use tiktoken load_dotenv(dotenv_path=".env", override=False) # Now import LightRAG (which will import tiktoken with the correct env var set) from lightrag import LightRAG from lightrag.utils import logger # Rest of the code...
- Create a
tiktoken_cachedirectory: If you don't have one already, create a directory namedtiktoken_cachein the project root. - Populate the cache: Run the
scripts/create_tiktoken_cache.pyscript to download the necessary tiktoken models into thetiktoken_cachedirectory. - Set the
TIKTOKEN_CACHE_DIRenvironment variable: Add the lineTIKTOKEN_CACHE_DIR=./tiktoken_cacheto your.envfile. - Disconnect from the internet: Disable your internet connection or put your machine in airplane mode.
- Run the application: Start the
RAG-Anythingapplication. For example:uv run examples/raganything_example.py requirements.txt
By following these steps, you can eliminate the network dependency and run the RAG-Anything project successfully in a fully offline environment.