Skip to content

Python Ollama embeddings with Poetry

Embeddings example

This example shows the smallest OpenAI Python SDK setup for calling POST /v1/embeddings through LunarGate into a local Ollama model.

Use this example when:

  • you want the smallest possible embeddings example
  • you want to test local Ollama with LunarGate before building RAG
  • you want to confirm that your gateway exposes /v1/embeddings

What it demonstrates

  • OpenAI(base_url=...) pointed at LunarGate
  • one client.embeddings.create(...) request
  • local Ollama as the upstream embedding provider
  • a minimal route matching /v1/embeddings

Run it

cp .env.example .env
poetry install

Make sure Ollama has the embedding model:

ollama pull nomic-embed-text-v2-moe

Start the gateway in a separate terminal:

cp config-simple.yaml.example config.yaml
lunargate --config ./config.yaml

Then run the client:

poetry run python main.py

What to inspect

  • main.py for the OpenAI SDK embeddings call
  • config-simple.yaml.example for the /v1/embeddings route
  • README.md for local Ollama requirements

Why this example matters

This is the shortest path from:

  • local embeddings in Ollama

To:

  • OpenAI-compatible embeddings through LunarGate

That makes it the right smoke test before you build semantic search, retrieval, or RAG on top.

Good companion pages

  • Read HTTP API for the public embeddings endpoint.
  • Read routing if you want separate chat and embeddings routes.