embedder
module wittgenstein_pgvector_qsql.embedder
Embedder implementations for Ollama and OpenAI, implementing LangChain's Embeddings contract.
Both classes expose .embed(text) for single-text use (gate, direct callers)
plus .embed_query() / .embed_documents() to satisfy the LangChain contract
so they can be passed directly to PGVector's embeddings parameter. They are
now thin wrappers over wittgenstein_embeddings — the generic provider
abstraction shared with wittgenstein_kg_client — kept under their original
names/signatures so existing callers (gate/embeddings.py,
training/service.py) don't need to change.
build_embedder(config) dispatches by provider via duck-typing: any object
that has the required attributes works — no inheritance needed.
Classes
-
EmbedderConfig — Structural protocol for embedder configuration.
-
OllamaEmbedder — Sync HTTP client for Ollama
/api/embeddings+ LangChain contract. -
OpenAIEmbedder — Sync OpenAI embeddings client + LangChain contract.
Functions
-
build_embedder — Factory that returns the embedder for the active provider.
wittgenstein_pgvector_qsql.embedder.EmbedderConfig
class EmbedderConfig()
Bases : Protocol
Structural protocol for embedder configuration.
Any object exposing these attributes works with build_embedder —
including an app's Settings, the core's config, or a plain dataclass.
wittgenstein_pgvector_qsql.embedder.OllamaEmbedder
class OllamaEmbedder(host: str, model: str, timeout_seconds: float = 60.0)
Bases : LangChainEmbeddingAdapter
Sync HTTP client for Ollama /api/embeddings + LangChain contract.
Logic now lives in wittgenstein_embeddings.OllamaEmbeddingClient — this
class is a backward-compat name/shape for existing callers.
Methods
wittgenstein_pgvector_qsql.embedder.OllamaEmbedder.embed
method OllamaEmbedder.embed(text: str) → list[float]
wittgenstein_pgvector_qsql.embedder.OpenAIEmbedder
class OpenAIEmbedder(api_key: str, model: str = 'text-embedding-3-small')
Bases : LangChainEmbeddingAdapter
Sync OpenAI embeddings client + LangChain contract.
Logic now lives in wittgenstein_embeddings.OpenAIEmbeddingClient — this
class is a backward-compat name/shape for existing callers.
Methods
wittgenstein_pgvector_qsql.embedder.OpenAIEmbedder.embed
method OpenAIEmbedder.embed(text: str) → list[float]
wittgenstein_pgvector_qsql.embedder.build_embedder
build_embedder(config: Any) → Embeddings
Factory that returns the embedder for the active provider.
Accepts any object with the `EmbedderConfig` attribute set (duck-typed)
an app's Settings, the lib's QSQLSettings, or a plain dataclass all work.
Parameters
-
config : Any — any object with
embedding_providerand the provider-specific fields listed inEmbedderConfig.
Raises
-
ValueError — unknown
embedding_provideror a required API key is missing.