I’m encountering a persistent network issue when trying to use the text2vec-ollama
module with a locally running Ollama instance, and I would be very grateful for some guidance.
My Goal: To have a Weaviate container (v1.31.2) use its text2vec-ollama
module to connect to an Ollama service running on the host machine (Ubuntu).
The Problem: When I try to insert data into a collection that uses the text2vec-ollama
vectorizer, the operation fails with a connection refused
error. The error log clearly shows that Weaviate is trying to connect to http://localhost:11434
, even though I have explicitly set the OLLAMA_API_ENDPOINT
environment variable to http://host.docker.internal:11434
.
1. Environment Details
- Weaviate Version:
1.31.2
(fromsemitechnologies/weaviate:1.31.2
image) - Weaviate Client: Python (
weaviate-client
, 4.15.2) - Docker Environment: Docker on Ubuntu Linux(24.04.2)
- Ollama Service: Running successfully on the host machine, accessible at
http://localhost:11434
from the host’s terminal.
2. My docker-compose.yml
Configuration
This is the configuration I am currently using, which includes various attempts to solve the issue.
services:
weaviate:
image: semitechnologies/weaviate:1.31.2
ports:
- "8080:8080"
- "50051:50051"
volumes:
- ./weaviate_data:/var/lib/weaviate
restart: on-failure:0
extra_hosts:
- "host.docker.internal:host-gateway"
environment:
QUERY_DEFAULTS_LIMIT: 25
AUTHENTICATION_ANONYMOUS_ACCESS_ENABLED: 'true'
PERSISTENCE_DATA_PATH: '/var/lib/weaviate'
DEFAULT_VECTORIZER_MODULE: 'none'
CLUSTER_HOSTNAME: 'node1'
ENABLE_TOKENIZER_GSE: 'true'
ENABLE_MODULES: 'text2vec-ollama,generative-ollama'
OLLAMA_API_ENDPOINT: 'http://host.docker.internal:11434'
3. Observed Behavior & Error Message
When I run my Python script to insert data, the batch insertion fails for all objects. The error message is consistently:
ERROR:weaviate-client:{'message': 'Failed to send all objects in a batch...', 'error': 'WeaviateInsertManyAllFailedError(\'Every object failed during insertion. Here is the set of all errors: send POST request: Post "http://localhost:11434/api/embeddings": dial tcp [::1]:11434: connect: connection refused\')'}
This confirms the module is trying to connect to localhost inside the container, not host.docker.internal.
4. Diagnostic Steps Already Taken
To isolate the problem, I have performed the following tests from inside the Weaviate container (docker compose exec weaviate /bin/sh
):
- Test 1: Internet Connectivity:
ping -c 4 8.8.8.8
→ SUCCESS. The container can reach the internet. - Test 2: Host DNS Resolution:
curl http://host.docker.internal:11434
→ FAILED withCould not resolve host: host.docker.internal
. This indicates that on my Linux system, this special DNS name is not resolving correctly. - Test 3: Collection Meta Info Check: Print the collection meta infomation, and two modules
generative-ollama
andtext2vec-ollama
have been loaded successfully.
{'grpcMaxMessageSize': 104858000, 'hostname': 'http://[::]:8080', 'modules': {'generative-ollama': {'documentationHref': 'https://github.com/ollama/ollama/blob/main/docs/api.md#generate-a-completion', 'name': 'Generative Search - Ollama'}, 'text2vec-ollama': {'documentationHref': 'https://github.com/ollama/ollama/blob/main/docs/api.md#generate-embeddings', 'name': 'Ollama Module'}}, 'version': '1.31.2'}
The only workaround I’ve found is to set network_mode: "host"
for the Weaviate service. While this works for local development, it’s not an ideal solution as it breaks network isolation.
5. A Tiny Python Test Case
import weaviate
import time
from weaviate.classes.config import Configure, Property, DataType, Tokenization
from weaviate.exceptions import WeaviateQueryException
# --- settings ---
COLLECTION_NAME = "KeywordSearchDiagnosticTest"
TEST_SENTENCE = "Weaviate是一个开源的向量数据库,非常适合RAG系统。"
def run_diagnostic():
client = None
try:
# --- step 1: connect to Weaviate and delete old test collection ---
print("--- step 1: connect to Weaviate and delete old test collection ---")
client = weaviate.connect_to_local()
if client.collections.exists(COLLECTION_NAME):
client.collections.delete(COLLECTION_NAME)
print(f"✅ delete the old test collection: '{COLLECTION_NAME}'。")
else:
print(f"✅ old test collection doesn't exit。")
# --- step2: create a new Collection ---
print("\n--- tep2: create a new Collection ---")
client.collections.create(
name=COLLECTION_NAME,
properties=[
Property(
name="content",
data_type=DataType.TEXT,
tokenization=Tokenization.GSE, # set tokenization to GSE
index_searchable=True
)
],
vectorizer_config=[Configure.NamedVectors.text2vec_ollama(
name="content_vector",
source_properties=["content"],
model="bge-m3:latest"
)]
)
print(f"✅ collection '{COLLECTION_NAME}' has been created successfully。")
# --- step 3: add a test info ---
print("\n--- step 3: add a test info ---")
collection = client.collections.get(COLLECTION_NAME)
uuid = collection.data.insert({
"content": TEST_SENTENCE
})
print(f"✅ add test info successfully,UUID: {uuid}...")
except Exception as e:
print(f"\n❌ meet issue or error: {e}")
finally:
if 'client' in locals() and client.is_connected():
client.close()
print("\n task completed, close the connection。")
if __name__ == "__main__":
run_diagnostic()
You need to dowload ollama and the embedding model before you run the above code