langchain_community.embeddings.ollama
.OllamaEmbeddings¶
- class langchain_community.embeddings.ollama.OllamaEmbeddings[source]¶
Bases:
BaseModel
,Embeddings
Ollama在本地运行大型语言模型。
要使用,请按照 https://ollama.ai/ 上的说明操作。
- 示例:
from langchain_community.embeddings import OllamaEmbeddings ollama_emb = OllamaEmbeddings( model="llama:7b", ) r1 = ollama_emb.embed_documents( [ "Alpha是希腊字母表的第一个字母", "Beta是希腊字母表的第二个字母", ] ) r2 = ollama_emb.embed_query( "希腊字母表的第二个字母是什么" )
Create a new model by parsing and validating input data from keyword arguments.
Raises ValidationError if the input data cannot be parsed to form a valid model.
- param base_url: str = 'http://localhost:11434'¶
模型托管的基本URL。
- param embed_instruction: str = 'passage: '¶
用于嵌入文档的指令。
- param headers: Optional[dict] = None¶
传递到端点的其他标头(例如授权,引用者)。 这在Ollama托管在需要身份验证令牌的云服务上时非常有用。
- param mirostat: Optional[int] = None¶
启用Mirostat采样以控制困惑度。 (默认值:0,0 = 禁用,1 = Mirostat,2 = Mirostat 2.0)
- param mirostat_eta: Optional[float] = None¶
影响算法对生成文本的反馈作出响应的速度。较低的学习率会导致调整速度较慢,而较高的学习率会使算法更具响应性。(默认值:0.1)
- param mirostat_tau: Optional[float] = None¶
控制输出的一致性和多样性之间的平衡。较低的值会导致更加聚焦和连贯的文本。(默认值:5.0)
- param model: str = 'llama2'¶
要使用的模型名称。
- param model_kwargs: Optional[dict] = None¶
其他模型关键字参数
- param num_ctx: Optional[int] = None¶
设置用于生成下一个标记的上下文窗口的大小。(默认值:2048)
- param num_gpu: Optional[int] = None¶
要使用的GPU数量。在macOS上,默认值为1,以启用Metal支持,为0则禁用。
- param num_thread: Optional[int] = None¶
设置计算过程中要使用的线程数。 默认情况下,Ollama会检测以获得最佳性能。 建议将此值设置为系统具有的物理CPU核心数(而不是逻辑核心数)。
- param query_instruction: str = 'query: '¶
用于嵌入查询的指令。
- param repeat_last_n: Optional[int] = None¶
设置模型向后查看的距离,以防止重复。(默认值:64,0 = 禁用,-1 = num_ctx)
- param repeat_penalty: Optional[float] = None¶
设置对重复的惩罚程度。较高的值(例如1.5)会更严厉地惩罚重复,而较低的值(例如0.9)则会更宽容。(默认值:1.1)
- param show_progress: bool = False¶
是否显示tqdm进度条。必须安装`tqdm`。
- param stop: Optional[List[str]] = None¶
设置要使用的停止标记。
- param temperature: Optional[float] = None¶
模型的温度。增加温度会使模型的回答更具创造性。(默认值:0.8)
- param tfs_z: Optional[float] = None¶
尾部自由抽样用于减少输出中不太可能的标记的影响。较高的值(例如2.0)将减少影响,而值为1.0将禁用此设置。(默认值:1)
- param top_k: Optional[int] = None¶
减少生成无意义内容的概率。较高的值(例如100)会产生更多不同的答案,而较低的值(例如10)会更保守。(默认值:40)
- param top_p: Optional[float] = None¶
与top-k一起使用。较高的值(例如,0.95)会导致生成更多样化的文本,而较低的值(例如,0.5)会生成更加集中和保守的文本。(默认值:0.9)
- async aembed_documents(texts: List[str]) List[List[float]] ¶
Asynchronous 嵌入搜索文档。
- Parameters
texts (List[str]) –
- Return type
List[List[float]]
- async aembed_query(text: str) List[float] ¶
Asynchronous 嵌入查询文本。
- Parameters
text (str) –
- Return type
List[float]
- classmethod construct(_fields_set: Optional[SetStr] = None, **values: Any) Model ¶
Creates a new model setting __dict__ and __fields_set__ from trusted or pre-validated data. Default values are respected, but no other validation is performed. Behaves as if Config.extra = ‘allow’ was set since it adds all passed values
- Parameters
_fields_set (Optional[SetStr]) –
values (Any) –
- Return type
Model
- copy(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, update: Optional[DictStrAny] = None, deep: bool = False) Model ¶
Duplicate a model, optionally choose which fields to include, exclude and change.
- Parameters
include (Optional[Union[AbstractSetIntStr, MappingIntStrAny]]) – fields to include in new model
exclude (Optional[Union[AbstractSetIntStr, MappingIntStrAny]]) – fields to exclude from new model, as with values this takes precedence over include
update (Optional[DictStrAny]) – values to change/add in the new model. Note: the data is not validated before creating the new model: you should trust this data
deep (bool) – set to True to make a deep copy of the model
self (Model) –
- Returns
new model instance
- Return type
Model
- dict(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, by_alias: bool = False, skip_defaults: Optional[bool] = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False) DictStrAny ¶
Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.
- Parameters
include (Optional[Union[AbstractSetIntStr, MappingIntStrAny]]) –
exclude (Optional[Union[AbstractSetIntStr, MappingIntStrAny]]) –
by_alias (bool) –
skip_defaults (Optional[bool]) –
exclude_unset (bool) –
exclude_defaults (bool) –
exclude_none (bool) –
- Return type
DictStrAny
- embed_documents(texts: List[str]) List[List[float]] [source]¶
使用Ollama部署的嵌入模型嵌入文档。
- 参数:
texts:要嵌入的文本列表。
- 返回:
每个文本的嵌入列表。
- Parameters
texts (List[str]) –
- Return type
List[List[float]]
- embed_query(text: str) List[float] [source]¶
使用Ollama部署的嵌入模型嵌入一个查询。
- 参数:
text: 要嵌入的文本。
- 返回:
文本的嵌入。
- Parameters
text (str) –
- Return type
List[float]
- classmethod from_orm(obj: Any) Model ¶
- Parameters
obj (Any) –
- Return type
Model
- json(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, by_alias: bool = False, skip_defaults: Optional[bool] = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, encoder: Optional[Callable[[Any], Any]] = None, models_as_dict: bool = True, **dumps_kwargs: Any) unicode ¶
Generate a JSON representation of the model, include and exclude arguments as per dict().
encoder is an optional function to supply as default to json.dumps(), other arguments as per json.dumps().
- Parameters
include (Optional[Union[AbstractSetIntStr, MappingIntStrAny]]) –
exclude (Optional[Union[AbstractSetIntStr, MappingIntStrAny]]) –
by_alias (bool) –
skip_defaults (Optional[bool]) –
exclude_unset (bool) –
exclude_defaults (bool) –
exclude_none (bool) –
encoder (Optional[Callable[[Any], Any]]) –
models_as_dict (bool) –
dumps_kwargs (Any) –
- Return type
unicode
- classmethod parse_file(path: Union[str, Path], *, content_type: unicode = None, encoding: unicode = 'utf8', proto: Protocol = None, allow_pickle: bool = False) Model ¶
- Parameters
path (Union[str, Path]) –
content_type (unicode) –
encoding (unicode) –
proto (Protocol) –
allow_pickle (bool) –
- Return type
Model
- classmethod parse_obj(obj: Any) Model ¶
- Parameters
obj (Any) –
- Return type
Model
- classmethod parse_raw(b: Union[str, bytes], *, content_type: unicode = None, encoding: unicode = 'utf8', proto: Protocol = None, allow_pickle: bool = False) Model ¶
- Parameters
b (Union[str, bytes]) –
content_type (unicode) –
encoding (unicode) –
proto (Protocol) –
allow_pickle (bool) –
- Return type
Model
- classmethod schema(by_alias: bool = True, ref_template: unicode = '#/definitions/{model}') DictStrAny ¶
- Parameters
by_alias (bool) –
ref_template (unicode) –
- Return type
DictStrAny
- classmethod schema_json(*, by_alias: bool = True, ref_template: unicode = '#/definitions/{model}', **dumps_kwargs: Any) unicode ¶
- Parameters
by_alias (bool) –
ref_template (unicode) –
dumps_kwargs (Any) –
- Return type
unicode
- classmethod update_forward_refs(**localns: Any) None ¶
Try to update ForwardRefs on fields based on this Model, globalns and localns.
- Parameters
localns (Any) –
- Return type
None
- classmethod validate(value: Any) Model ¶
- Parameters
value (Any) –
- Return type
Model