Skip to content

Commit

Permalink
[feat]
Browse files Browse the repository at this point in the history
add options parameter to embed_documents and embed_query methods in OllamaEmbeddings
  • Loading branch information
SyedBaqarAbbas committed Jan 19, 2025
1 parent e9abe58 commit 14b5d78
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions libs/partners/ollama/langchain_ollama/embeddings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
from typing import (
List,
Optional,
Union,
Mapping,
Any,
)

from langchain_core.embeddings import Embeddings
from ollama import AsyncClient, Client
from ollama._types import Options
from pydantic import (
BaseModel,
ConfigDict,
Expand Down Expand Up @@ -156,14 +160,14 @@ def _set_clients(self) -> Self:
self._async_client = AsyncClient(host=self.base_url, **client_kwargs)
return self

def embed_documents(self, texts: List[str]) -> List[List[float]]:
def embed_documents(self, texts: List[str], options: Optional[Union[Mapping[str, Any], Options]] = None) -> List[List[float]]:

Check failure on line 163 in libs/partners/ollama/langchain_ollama/embeddings.py

View workflow job for this annotation

GitHub Actions / cd libs/partners/ollama / make lint #3.13

Ruff (E501)

langchain_ollama/embeddings.py:163:89: E501 Line too long (130 > 88)

Check failure on line 163 in libs/partners/ollama/langchain_ollama/embeddings.py

View workflow job for this annotation

GitHub Actions / cd libs/partners/ollama / make lint #3.9

Ruff (E501)

langchain_ollama/embeddings.py:163:89: E501 Line too long (130 > 88)
"""Embed search docs."""
embedded_docs = self._client.embed(self.model, texts)["embeddings"]
embedded_docs = self._client.embed(self.model, texts, options=options)["embeddings"]

Check failure on line 165 in libs/partners/ollama/langchain_ollama/embeddings.py

View workflow job for this annotation

GitHub Actions / cd libs/partners/ollama / make lint #3.13

Ruff (E501)

langchain_ollama/embeddings.py:165:89: E501 Line too long (92 > 88)

Check failure on line 165 in libs/partners/ollama/langchain_ollama/embeddings.py

View workflow job for this annotation

GitHub Actions / cd libs/partners/ollama / make lint #3.9

Ruff (E501)

langchain_ollama/embeddings.py:165:89: E501 Line too long (92 > 88)
return embedded_docs

def embed_query(self, text: str) -> List[float]:
def embed_query(self, text: str, options: Optional[Union[Mapping[str, Any], Options]] = None) -> List[float]:

Check failure on line 168 in libs/partners/ollama/langchain_ollama/embeddings.py

View workflow job for this annotation

GitHub Actions / cd libs/partners/ollama / make lint #3.13

Ruff (E501)

langchain_ollama/embeddings.py:168:89: E501 Line too long (113 > 88)

Check failure on line 168 in libs/partners/ollama/langchain_ollama/embeddings.py

View workflow job for this annotation

GitHub Actions / cd libs/partners/ollama / make lint #3.9

Ruff (E501)

langchain_ollama/embeddings.py:168:89: E501 Line too long (113 > 88)
"""Embed query text."""
return self.embed_documents([text])[0]
return self.embed_documents([text], options=options)[0]

async def aembed_documents(self, texts: List[str]) -> List[List[float]]:
"""Embed search docs."""
Expand Down

0 comments on commit 14b5d78

Please sign in to comment.