Embeddings
zenpyre.embeddings ¶
Contain embedding models.
zenpyre.embeddings.inspect_embeddings ¶
inspect_embeddings(
vector_store: VectorStore, n: int = 2
) -> None
Log a summary of documents retrieved from a vector store.
Retrieves the first n documents via
:meth:~langchain_core.vectorstores.VectorStore.similarity_search
and logs each document's ID, source metadata, and text content.
.. note::
Unlike the Chroma-specific implementation, this function works
on any :class:~langchain_core.vectorstores.VectorStore backend
but does not show embedding vectors, as there is no standard
cross-provider API for retrieving raw embeddings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vector_store
|
VectorStore
|
Any
:class: |
required |
n
|
int
|
Number of documents to preview. Defaults to |
2
|
zenpyre.embeddings.resolve_embeddings ¶
resolve_embeddings(
embeddings: Embeddings | dict[str, Any] | BaseConfig,
) -> Embeddings
Resolve a LangChain
:class:~langchain_core.embeddings.Embeddings instance from an
existing object, a configuration dictionary, or a
:class:~zenpyre.utils.config.BaseConfig.
If embeddings is already an
:class:~langchain_core.embeddings.Embeddings instance it is
returned as-is. If it is a :class:dict or a
:class:~zenpyre.utils.config.BaseConfig, it is treated as an
objectory factory configuration and instantiated via
:func:objectory.factory. See
:func:~zenpyre.utils.resolve.resolve_object for details.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
embeddings
|
Embeddings | dict[str, Any] | BaseConfig
|
Either a fully configured
:class: |
required |
Returns:
| Type | Description |
|---|---|
Embeddings
|
A configured :class: |
Embeddings
|
instance. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the resolved object is not a
:class: |
Example
>>> from zenpyre.embeddings import resolve_embeddings
>>> # From an existing instance:
>>> from langchain_core.embeddings.fake import FakeEmbeddings
>>> embeddings = resolve_embeddings(FakeEmbeddings(size=128))
>>> # From a configuration dictionary:
>>> embeddings = resolve_embeddings(
... {"_target_": "langchain_ollama.OllamaEmbeddings", "model": "nomic-embed-text"}
... )
zenpyre.embeddings.factory ¶
Contain embedding factories.
zenpyre.embeddings.factory.BaseEmbeddingsFactory ¶
Bases: ABC
Abstract base class for embedding model factories.
Subclasses implement :meth:make_embedding to instantiate and return
a configured :class:~langchain_core.factory.Embeddings object.
This pattern decouples embedding creation from the rest of the
codebase, making it easy to swap providers (e.g. Ollama, OpenAI,
HuggingFace) without changing call sites.
Example
>>> from langchain_ollama import OllamaEmbeddings
>>> from zenpyre.embeddings.factory import BaseEmbeddingsFactory
>>> class OllamaEmbeddingsFactory(BaseEmbeddingsFactory):
... def make_embeddings(self) -> OllamaEmbeddings:
... return OllamaEmbeddings(model="nomic-embed-text")
...
zenpyre.embeddings.factory.BaseEmbeddingsFactory.make_embeddings
abstractmethod
¶
make_embeddings() -> Embeddings
Create and return a configured embedding model instance.
Returns:
| Name | Type | Description |
|---|---|---|
A |
Embeddings
|
class: |
zenpyre.embeddings.factory.ConfigurableEmbeddingsFactory ¶
Bases: BaseEmbeddingsFactory, MultilineDisplayMixin
A concrete embedding factory that accepts either a pre-built
:class:~langchain_core.embeddings.Embeddings instance or a
configuration dictionary.
When a dict is provided it is resolved at each
:meth:make_embeddings call via :func:~resolve_embeddings,
which uses objectory to instantiate the configured class.
When an instance is provided it is returned as-is.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
embeddings
|
Embeddings | dict[str, Any]
|
A fully configured
:class: |
required |
Example
>>> from langchain_core.embeddings.fake import FakeEmbeddings
>>> from zenpyre.embeddings.factory import ConfigurableEmbeddingsFactory
>>> factory = ConfigurableEmbeddingsFactory(FakeEmbeddings(size=128))
>>> embeddings = factory.make_embeddings()
zenpyre.embeddings.factory.EmbeddingsFactory ¶
Bases: BaseEmbeddingsFactory, MultilineDisplayMixin
A concrete embedding factory that wraps a pre-built
:class:~langchain_core.embeddings.Embeddings instance.
Use this when the embedding model is already instantiated and you
simply want to wrap it in the :class:~BaseEmbeddingsFactory
interface — for example, when injecting a fixed embedding model
into a component that expects a factory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
embeddings
|
Embeddings
|
A fully configured
:class: |
required |
Example
>>> from langchain_ollama import OllamaEmbeddings
>>> from zenpyre.embeddings.factory import EmbeddingsFactory
>>> factory = EmbeddingsFactory(OllamaEmbeddings(model="nomic-embed-text"))
>>> embeddings = factory.make_embeddings()
zenpyre.embeddings.factory.HuggingFaceEmbeddingsFactory ¶
Bases: BaseEmbeddingsFactory, InlineDisplayMixin
A concrete embedding factory that wraps a pre-built
:class:~langchain_core.embeddings.Embeddings instance.
Use this when the embedding model is already instantiated and you
simply want to wrap it in the :class:~BaseEmbeddingsFactory
interface — for example, when injecting a fixed embedding model
into a component that expects a factory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
embeddings
|
A fully configured
:class: |
required |
Example
>>> from zenpyre.embeddings.factory import HuggingFaceEmbeddingsFactory
>>> factory = HuggingFaceEmbeddingsFactory(model_name="all-MiniLM-L6-v2")
>>> embeddings = factory.make_embeddings() # doctest: +SKIP