Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing options in OllamaEmbeddings of langchain_ollama.embeddings after migration from langchain_community.embeddings #29294

Open
5 tasks done
SyedBaqarAbbas opened this issue Jan 19, 2025 · 0 comments
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature

Comments

@SyedBaqarAbbas
Copy link
Contributor

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

Example Code

There are no options to set parameters such as max tokens in OllamaEmbeddings imported from langchain_ollama.
Running the following code yields errors:

from langchain_ollama import OllamaEmbeddings

embedding_client = OllamaEmbeddings(
    base_url="http://localhost:11434",
    model="nomic-embed-text",
    num_ctx=6144,
)

Previously, these were available:

from langchain_community.embeddings import OllamaEmbeddings

embedding_client = OllamaEmbeddings(
    base_url="http://localhost:11434",
    model="nomic-embed-text",
    num_ctx=6144,
)

Error Message and Stack Trace (if applicable)

If the user tries to set the configurations like before, the following trace occurs:

(langchain) root@50aff4a67851:/workspace/libs/partners/ollama# python /workspace/libs/community/test.py 
Traceback (most recent call last):
  File "/workspace/libs/community/test.py", line 9, in <module>
    ollama_emb = OllamaEmbeddings(
  File "/root/miniconda3/envs/langchain/lib/python3.9/site-packages/pydantic/main.py", line 214, in __init__
    validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
pydantic_core._pydantic_core.ValidationError: 1 validation error for OllamaEmbeddings
num_ctx
  Extra inputs are not permitted [type=extra_forbidden, input_value=1024, input_type=int]
    For further information visit https://errors.pydantic.dev/2.10/v/extra_forbidden

Note: This error occurs because this functionality was removed but it is much needed.

Description

I am trying to use OllamaEmbeddings imported from langchain_ollama. The issue arises that options that were previously available are (such as num_ctx) not available now.

Discussed in #29113

Originally posted by Marsman1996 January 9, 2025
For OllamaEmbeddings from langchain_community.embeddings, I can use the following code to set max tokens:

embedding_client = OllamaEmbeddings(
    base_url=f"http://localhost:11434",
    model="nomic-embed-text",
    num_ctx=6144,
)

But how to set max tokens for OllamaEmbeddings from langchain_ollama.embeddings?

System Info

System Information

OS: Linux
OS Version: #41~22.04.2-Ubuntu SMP PREEMPT_DYNAMIC Mon Jun 3 11:32:55 UTC 2
Python Version: 3.9.21 (main, Dec 11 2024, 16:24:11)
[GCC 11.2.0]

Package Information

langchain_core: 0.3.30
langchain: 0.3.14
langchain_community: 0.3.14
langsmith: 0.2.3
langchain_ollama: 0.2.2
langchain_tests: 0.3.8
langchain_text_splitters: 0.3.5

Optional packages not installed

langserve

Other Dependencies

aiohttp: 3.11.11
async-timeout: 4.0.3
dataclasses-json: 0.6.7
httpx: 0.27.2
httpx-sse: 0.4.0
jsonpatch: 1.33
langsmith-pyo3: Installed. No version info available.
numpy: 1.26.4
ollama: 0.4.4
orjson: 3.10.12
packaging: 24.2
pydantic: 2.10.4
pydantic-settings: 2.7.0
pytest: 7.4.4
pytest-asyncio: 0.23.8
pytest-socket: 0.7.0
PyYAML: 6.0.2
requests: 2.32.3
requests-toolbelt: 1.0.0
SQLAlchemy: 2.0.36
syrupy: 4.8.0
tenacity: 9.0.0
typing-extensions: 4.12.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature
Projects
None yet
Development

No branches or pull requests

1 participant