Skip to content

Configuration ​

LocalRAG is configured with environment variables, read once when the server starts. To change a setting, set the variable and restart LocalRAG.

Environment variables ​

VariableDefaultWhat it sets
LOCALRAG_HOST127.0.0.1The network address the server listens on. 127.0.0.1 means only this computer.
LOCALRAG_PORT8090The port the server listens on.
LOCALRAG_DATA_DIR./dataThe folder for the vector store and the document list.
LOCALRAG_OLLAMA_URLhttp://localhost:11434The address of the Ollama server.
LOCALRAG_MODELllama3.2The Ollama model that writes answers.
LOCALRAG_EMBED_MODELBAAI/bge-small-en-v1.5The sentence-transformers model that makes embeddings.
LOCALRAG_TOP_K5How many passages to retrieve for each question, if the request does not say.
LOCALRAG_SCORE_THRESHOLD0.30The lowest similarity score a passage needs to be used.
LOCALRAG_CHUNK_TOKENS500The largest chunk, in tokens.
LOCALRAG_CHUNK_OVERLAP50About how many tokens neighbouring chunks on the same page share.

A value that is not a number where a number is expected stops the server at start-up with a message such as invalid integer value for LOCALRAG_PORT.

Set a variable with pip ​

Put the variable in front of the command for one run:

bash
LOCALRAG_PORT=9000 LOCALRAG_MODEL=mistral localrag serve

Or export it for the whole terminal session:

bash
export LOCALRAG_DATA_DIR="$HOME/localrag-data"
localrag serve

Set a variable with Docker ​

Add it under environment: for the localrag service in docker-compose.yml, then run docker compose up -d again:

yaml
  localrag:
    environment:
      - LOCALRAG_OLLAMA_URL=http://ollama:11434
      - LOCALRAG_MODEL=mistral
      - LOCALRAG_SCORE_THRESHOLD=0.25

The Docker image already sets LOCALRAG_HOST=0.0.0.0 and LOCALRAG_DATA_DIR=/data, and the Compose file points LOCALRAG_OLLAMA_URL at the ollama container.

Tuning retrieval ​

If you seeTry
Too many "I don't know" answers to questions your documents do answerLower LOCALRAG_SCORE_THRESHOLD a little, for example to 0.25.
Answers that drift into unrelated passagesRaise LOCALRAG_SCORE_THRESHOLD, or lower LOCALRAG_TOP_K.
Answers that miss details spread over many placesRaise LOCALRAG_TOP_K.

LOCALRAG_CHUNK_TOKENS and LOCALRAG_CHUNK_OVERLAP only affect documents added after the change. To apply new values to existing documents, delete them and add them again.

Command-line commands ​

CommandWhat it does
localrag serveStarts the web server and API with the settings above.
localrag ingest PATHAdds a file, or every .pdf, .txt and .md file in a folder and its subfolders. Prints a line per file and a summary, and exits with status 1 if nothing was added.

Where data is stored ​

InstallLocation
pipThe folder in LOCALRAG_DATA_DIR, by default data in the folder where you start LocalRAG
DockerThe localrag-data volume, mounted at /data in the container

Inside the data folder, docs.json lists the documents and chroma/ holds the vector store. In Docker, the downloaded embedding model is kept there too, under hf/. Ollama models are kept by Ollama, in the ollama volume under Docker.

To start again with no documents, stop LocalRAG and delete the data folder, or run docker compose down -v (which also deletes the Ollama models).

Next steps ​