error when create embedding model: An error occurred during credentials validation: Session.request() got an unexpected keyword argument 'options' #5610

Closed
opened 2026-02-21 18:11:52 -05:00 by yindo · 2 comments
Owner

Originally created by @victorming666 on GitHub (Sep 13, 2024).

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.8.0

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

settings -> ollama -> create model -> embedding model:
ollama + smartcreation/bge-large-zh-v1.5:latest
image

✔️ Expected Behavior

create the embedding model hosted by ollama

Actual Behavior

An error occurred during credentials validation: Session.request() got an unexpected keyword argument 'options'

Originally created by @victorming666 on GitHub (Sep 13, 2024). ### Self Checks - [X] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [X] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [X] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [X] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [X] Please do not modify this template :) and fill in all the required fields. ### Dify version 0.8.0 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce settings -> ollama -> create model -> embedding model: ollama + smartcreation/bge-large-zh-v1.5:latest ![image](https://github.com/user-attachments/assets/56744fe0-b448-4088-a350-613f276c12ce) ### ✔️ Expected Behavior create the embedding model hosted by ollama ### ❌ Actual Behavior An error occurred during credentials validation: Session.request() got an unexpected keyword argument 'options'
yindo added the 🐞 bug label 2026-02-21 18:11:52 -05:00
yindo closed this issue 2026-02-21 18:11:52 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Sep 13, 2024):

@victorming666 Hello there! 👋 I'm here to help you with bugs, questions, and becoming a contributor. Let's squash those bugs together!

The error "Session.request() got an unexpected keyword argument 'options'" during credentials validation when creating an embedding model in Dify version 0.8.0 can be resolved by removing the 'options' keyword argument from the payload in the _invoke method.

Here is the corrected code snippet:

def _invoke(
    self, model: str, credentials: dict, texts: list[str], user: Optional[str] = None
) -> TextEmbeddingResult:
    """
    Invoke text embedding model

    :param model: model name
    :param credentials: model credentials
    :param texts: texts to embed
    :param user: unique user id
    :return: embeddings result
    """

    # Prepare headers and payload for the request
    headers = {"Content-Type": "application/json"}

    endpoint_url = credentials.get("base_url")
    if not endpoint_url.endswith("/"):
        endpoint_url += "/"

    endpoint_url = urljoin(endpoint_url, "api/embed")

    # get model properties
    context_size = self._get_context_size(model, credentials)

    inputs = []
    used_tokens = 0

    for text in texts:
        # Here token count is only an approximation based on the GPT2 tokenizer
        num_tokens = self._get_num_tokens_by_gpt2(text)

        if num_tokens >= context_size:
            cutoff = int(np.floor(len(text) * (context_size / num_tokens)))
            # if num tokens is larger than context length, only use the start
            inputs.append(text[0:cutoff])
        else:
            inputs.append(text)

    # Prepare the payload for the request
    payload = {"input": inputs, "model": model}

    # Make the request to the Ollama API
    response = requests.post(endpoint_url, headers=headers, data=json.dumps(payload), timeout=(10, 300))

    response.raise_for_status()  # Raise an exception for HTTP errors
    response_data = response.json()

    # Extract embeddings and used tokens from the response
    embeddings = response_data["embeddings"]
    embedding_used_tokens = self.get_num_tokens(model, credentials, inputs)
    used_tokens += embedding_used_tokens

    # calc usage
    usage = self._calc_response_usage(model=model, credentials=credentials, tokens=used_tokens)

    return TextEmbeddingResult(embeddings=embeddings, usage=usage, model=model)

By removing the "options": {"use_mmap": True} from the payload, the error should be resolved [1].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Sep 13, 2024): <!-- Greeting --> @victorming666 Hello there! 👋 I'm here to help you with bugs, questions, and becoming a contributor. Let's squash those bugs together! <!-- Answer --> The error "Session.request() got an unexpected keyword argument 'options'" during credentials validation when creating an embedding model in Dify version 0.8.0 can be resolved by removing the 'options' keyword argument from the payload in the `_invoke` method. Here is the corrected code snippet: ```python def _invoke( self, model: str, credentials: dict, texts: list[str], user: Optional[str] = None ) -> TextEmbeddingResult: """ Invoke text embedding model :param model: model name :param credentials: model credentials :param texts: texts to embed :param user: unique user id :return: embeddings result """ # Prepare headers and payload for the request headers = {"Content-Type": "application/json"} endpoint_url = credentials.get("base_url") if not endpoint_url.endswith("/"): endpoint_url += "/" endpoint_url = urljoin(endpoint_url, "api/embed") # get model properties context_size = self._get_context_size(model, credentials) inputs = [] used_tokens = 0 for text in texts: # Here token count is only an approximation based on the GPT2 tokenizer num_tokens = self._get_num_tokens_by_gpt2(text) if num_tokens >= context_size: cutoff = int(np.floor(len(text) * (context_size / num_tokens))) # if num tokens is larger than context length, only use the start inputs.append(text[0:cutoff]) else: inputs.append(text) # Prepare the payload for the request payload = {"input": inputs, "model": model} # Make the request to the Ollama API response = requests.post(endpoint_url, headers=headers, data=json.dumps(payload), timeout=(10, 300)) response.raise_for_status() # Raise an exception for HTTP errors response_data = response.json() # Extract embeddings and used tokens from the response embeddings = response_data["embeddings"] embedding_used_tokens = self.get_num_tokens(model, credentials, inputs) used_tokens += embedding_used_tokens # calc usage usage = self._calc_response_usage(model=model, credentials=credentials, tokens=used_tokens) return TextEmbeddingResult(embeddings=embeddings, usage=usage, model=model) ``` By removing the `"options": {"use_mmap": True}` from the payload, the error should be resolved <sup>[[1]](https://github.com/langgenius/dify/issues/8339)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@crazywoola commented on GitHub (Sep 13, 2024):

Please upgrade to v0.8.2

@crazywoola commented on GitHub (Sep 13, 2024): Please upgrade to v0.8.2
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#5610