# Local (offline) embeddings The server can embed documents and queries with a local `sentence-transformers` model loaded in-process. No OpenAI key, and no network calls are needed at serve or index time once the chosen model is saved locally. If the server does not have access to the HuggingFace endpoint, the model will need to be downloaded on a machine with network access and copied across (see `Air-gapped / offline setup` below). #### NOTE This is one of two ways to run without the public OpenAI API. Use a **local model** (this page) when you want no network calls at all. Use an OpenAI-compatible **server** (see `OpenAI-compatible server`) when a shared endpoint already hosts your embedding model. Both avoid OpenAI egress. ## Configuration To configure the MCP Server with local embeddings we use `ONETICK_DB_EMBEDDING_TYPE=sentence_transformer` (documented fully in the `Embeddings` section of the configuration page): | Variable | Value | |------------------------------|----------------------------------------------------------------------------------------------------| | `ONETICK_DB_EMBEDDING_TYPE` | `sentence_transformer` | | `ONETICK_DB_EMBEDDING_MODEL` | A HuggingFace model name (e.g. `all-MiniLM-L6-v2`), or an absolute path to a local model directory | The `local-embeddings` extra is required at install time: ``` pip install "onetick-mcp" "onetick-llmbase[local-embeddings]" ``` By default the model is downloaded from HuggingFace on first use and cached under `HF_HOME`. See `Network requirements` for the allowlist. If your server does not have network access to HuggingFace endpoints then see the `Air-gapped / offline setup` section below. ## Windows startup Local embeddings use PyTorch to run the model. On Windows, the index builder and the server (with document search enabled) load PyTorch before OneTick. This order addresses a reported `c10.dll` / `WinError 1114` initialization failure when OneTick was imported first. Use the normal index-build and server commands; no manual `import torch` wrapper or new environment setting is required. The `local-embeddings` extra above must be installed in the same virtual environment. If PyTorch is missing or its DLLs cannot initialize, the error is raised during startup. Remote embeddings and servers serving only reference-data or OneTick query tools do not preload PyTorch. ## Using an internal artifact registry If your registry proxies Hugging Face (mirroring requests to `huggingface.co`), you can reference the model by name and let `HF_ENDPOINT` redirect the download: ``` ONETICK_DB_EMBEDDING_TYPE=sentence_transformer ONETICK_DB_EMBEDDING_MODEL=all-MiniLM-L6-v2 HF_ENDPOINT=https://artifacts.example.com/huggingface ``` `HF_ENDPOINT` is read by the HuggingFace libraries themselves, not by the server’s settings. Confirm with your platform team that the registry mirrors the specific model repo you need. Not every proxy mirrors the full HuggingFace catalog. This replaces the `huggingface.co` entry in `Network requirements` with your registry’s endpoint instead. ## Air-gapped / offline setup If the MCP server has no outbound access to `huggingface.co`, download the model on a separate machine that does have access, then copy it across. See the worked example below using the `all-MiniLM-L6-v2` model. For more information, see the `Transformers offline mode docs`. ### 1. Download the model on a machine with internet access Use a different machine that has network access. Only the `huggingface_hub` package is needed: ### pip ``` pip install huggingface_hub hf download sentence-transformers/all-MiniLM-L6-v2 --local-dir ./all-MiniLM-L6-v2 ``` ### uv ``` uv run --with huggingface_hub hf download sentence-transformers/all-MiniLM-L6-v2 --local-dir ./all-MiniLM-L6-v2 ``` This downloads the model files into `./all-MiniLM-L6-v2`. This is the directory to copy across. See the `hf CLI download docs` for more options. ### 2. Transfer the model directory to the air-gapped server Package the directory and transfer it to the remote server using your standard offline transfer process (secure copy, removable media, internal file drop, etc): ``` tar -czf all-MiniLM-L6-v2.tar.gz all-MiniLM-L6-v2 ``` On the target server, extract it to wherever you keep local models, e.g.: ``` sudo mkdir -p /opt/models sudo tar -xzf all-MiniLM-L6-v2.tar.gz -C /opt/models ``` The model is now at `/opt/models/all-MiniLM-L6-v2/` ### 3. Point the server at the local directory and disable network lookups ``` ONETICK_DB_EMBEDDING_TYPE=sentence_transformer ONETICK_DB_EMBEDDING_MODEL=/opt/models/all-MiniLM-L6-v2 HF_HUB_OFFLINE=1 TRANSFORMERS_OFFLINE=1 ``` `HF_HUB_OFFLINE` / `TRANSFORMERS_OFFLINE` are read by the HuggingFace libraries themselves, not by the server’s settings. Both the server and `build_index` load `.env` from the working directory, so setting them there applies to both indexing and serving. #### NOTE `HF_HOME` (the cache directory) is not needed when `ONETICK_DB_EMBEDDING_MODEL` references the absolute path to the model, as above. Set `HF_HOME` only if you instead reference a model by name (e.g. `ONETICK_DB_EMBEDDING_MODEL=all-MiniLM-L6-v2`) from a pre-populated cache directory copied across wholesale, rather than a single model’s saved directory. ### 4. Verify it loads with no network access Confirm the local embedding model is set up correctly on the server. Run the command below from the same virtual environment where OneTick MCP is installed: ``` HF_HUB_OFFLINE=1 TRANSFORMERS_OFFLINE=1 python -c " from sentence_transformers import SentenceTransformer model = SentenceTransformer('/opt/models/all-MiniLM-L6-v2') print(model.encode('hello world').shape) " ``` That should print `(384,)` (`all-MiniLM-L6-v2`’s embedding dimension) with no outbound requests. If it instead raises a connection error, double check the directory was extracted correctly and that the path above matches where you extracted it. ## Re-index after changing the model Switching to a local model, or changing `ONETICK_DB_EMBEDDING_MODEL`, requires rebuilding the search index - see `Re-index after changing the model`.