Skip to content

Comments

feat(examples): add custom HTTP embedding example for LM Studio / Ollama#149

Open
cluster2600 wants to merge 1 commit intoalibaba:mainfrom
cluster2600:feat/lmstudio-custom-http-embedding
Open

feat(examples): add custom HTTP embedding example for LM Studio / Ollama#149
cluster2600 wants to merge 1 commit intoalibaba:mainfrom
cluster2600:feat/lmstudio-custom-http-embedding

Conversation

@cluster2600
Copy link
Contributor

Summary

This PR adds a self-contained example showing how to use any OpenAI-compatible HTTP embedding endpoint (LM Studio, Ollama, vLLM, LocalAI, …) as the embedding source in zvec.

What's added

examples/custom_http_embedding.py

HTTPEmbeddingFunction A zero-dependency class (stdlib only) that calls any /v1/embeddings endpoint, caches results with @lru_cache, and satisfies the DenseEmbeddingFunction protocol.
Collection setup HNSW index with cosine similarity, dimension auto-detected from the server response.
Insert + query 5 sample documents embedded on the fly, then a semantic search query.
CLI interface --base-url, --model, --api-key, --collection-path flags for easy customisation.
README-style header Step-by-step instructions for LM Studio and Ollama embedded at the top of the file.

Usage

# LM Studio (default)
python examples/custom_http_embedding.py

# Ollama
python examples/custom_http_embedding.py \
    --base-url http://localhost:11434 \
    --model nomic-embed-text

Motivation

The existing extensions (OpenAIDenseEmbedding, etc.) require the openai package and are primarily designed for cloud APIs. Many developers want to use local inference servers without extra dependencies. This example shows the pattern using only Python stdlib, making it easy to adapt or inline.

Testing

The example runs end-to-end against a live LM Studio instance on localhost:1234. No new test infrastructure is required for a standalone script.

@CLAassistant
Copy link

CLAassistant commented Feb 19, 2026

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants