mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-12 06:29:03 +08:00
fix: update usage for Jina Embeddings v3 (#8771)
This commit is contained in:
parent
0c96f0aa51
commit
4c9ef6e830
@ -67,46 +67,3 @@ model_credential_schema:
|
||||
required: false
|
||||
type: text-input
|
||||
default: '8192'
|
||||
- variable: task
|
||||
label:
|
||||
zh_Hans: 下游任务
|
||||
en_US: Downstream task
|
||||
placeholder:
|
||||
zh_Hans: 选择将使用向量模型的下游任务。模型将返回针对该任务优化的向量。
|
||||
en_US: Select the downstream task for which the embeddings will be used. The model will return the optimized embeddings for that task.
|
||||
required: false
|
||||
type: select
|
||||
options:
|
||||
- value: retrieval.query
|
||||
label:
|
||||
en_US: retrieval.query
|
||||
- value: retrieval.passage
|
||||
label:
|
||||
en_US: retrieval.passage
|
||||
- value: separation
|
||||
label:
|
||||
en_US: separation
|
||||
- value: classification
|
||||
label:
|
||||
en_US: classification
|
||||
- value: text-matching
|
||||
label:
|
||||
en_US: text-matching
|
||||
- variable: dimensions
|
||||
label:
|
||||
zh_Hans: 输出维度
|
||||
en_US: Output dimensions
|
||||
placeholder:
|
||||
zh_Hans: 输入您的输出维度
|
||||
en_US: Enter output dimensions
|
||||
required: false
|
||||
type: text-input
|
||||
- variable: late_chunking
|
||||
label:
|
||||
zh_Hans: 后期分块
|
||||
en_US: Late chunking
|
||||
placeholder:
|
||||
zh_Hans: 应用后期分块技术来利用模型的长上下文功能来生成上下文块向量化。
|
||||
en_US: Apply the late chunking technique to leverage the model's long-context capabilities for generating contextual chunk embeddings.
|
||||
required: false
|
||||
type: switch
|
||||
|
@ -28,7 +28,7 @@ class JinaTextEmbeddingModel(TextEmbeddingModel):
|
||||
|
||||
api_base: str = "https://api.jina.ai/v1"
|
||||
|
||||
def _to_payload(self, model: str, texts: list[str], credentials: dict) -> dict:
|
||||
def _to_payload(self, model: str, texts: list[str], credentials: dict, input_type: EmbeddingInputType) -> dict:
|
||||
"""
|
||||
Parse model credentials
|
||||
|
||||
@ -45,18 +45,10 @@ class JinaTextEmbeddingModel(TextEmbeddingModel):
|
||||
|
||||
data = {"model": model, "input": [transform_jina_input_text(model, text) for text in texts]}
|
||||
|
||||
task = credentials.get("task")
|
||||
dimensions = credentials.get("dimensions")
|
||||
late_chunking = credentials.get("late_chunking")
|
||||
|
||||
if task is not None:
|
||||
data["task"] = task
|
||||
|
||||
if dimensions is not None:
|
||||
data["dimensions"] = int(dimensions)
|
||||
|
||||
if late_chunking is not None:
|
||||
data["late_chunking"] = late_chunking
|
||||
# model specific parameters
|
||||
if model == "jina-embeddings-v3":
|
||||
# set `task` type according to input type for the best performance
|
||||
data["task"] = "retrieval.query" if input_type == EmbeddingInputType.QUERY else "retrieval.passage"
|
||||
|
||||
return data
|
||||
|
||||
@ -88,7 +80,7 @@ class JinaTextEmbeddingModel(TextEmbeddingModel):
|
||||
url = base_url + "/embeddings"
|
||||
headers = {"Authorization": "Bearer " + api_key, "Content-Type": "application/json"}
|
||||
|
||||
data = self._to_payload(model=model, texts=texts, credentials=credentials)
|
||||
data = self._to_payload(model=model, texts=texts, credentials=credentials, input_type=input_type)
|
||||
|
||||
try:
|
||||
response = post(url, headers=headers, data=dumps(data))
|
||||
|
Loading…
x
Reference in New Issue
Block a user