OllamaEmbeddings#
- class langchain_community.embeddings.ollama.OllamaEmbeddings[source]#
Bases:
BaseModel
,Embeddings
Deprecated since version 0.3.1: Use
:class:`~langchain_ollama.OllamaEmbeddings`
instead.Ollama locally runs large language models.
To use, follow the instructions at https://ollama.ai/.
Example
from langchain_community.embeddings import OllamaEmbeddings ollama_emb = OllamaEmbeddings( model="llama:7b", ) r1 = ollama_emb.embed_documents( [ "Alpha is the first letter of Greek alphabet", "Beta is the second letter of Greek alphabet", ] ) r2 = ollama_emb.embed_query( "What is the second letter of Greek alphabet" )
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- param base_url: str = 'http://localhost:11434'#
Base url the model is hosted under.
- param embed_instruction: str = 'passage: '#
Instruction used to embed documents.
- param headers: dict | None = None#
Additional headers to pass to endpoint (e.g. Authorization, Referer). This is useful when Ollama is hosted on cloud services that require tokens for authentication.
- param mirostat: int | None = None#
Enable Mirostat sampling for controlling perplexity. (default: 0, 0 = disabled, 1 = Mirostat, 2 = Mirostat 2.0)
- param mirostat_eta: float | None = None#
Influences how quickly the algorithm responds to feedback from the generated text. A lower learning rate will result in slower adjustments, while a higher learning rate will make the algorithm more responsive. (Default: 0.1)
- param mirostat_tau: float | None = None#
Controls the balance between coherence and diversity of the output. A lower value will result in more focused and coherent text. (Default: 5.0)
- param model: str = 'llama2'#
Model name to use.
- param model_kwargs: dict | None = None#
Other model keyword args
- param num_ctx: int | None = None#
Sets the size of the context window used to generate the next token. (Default: 2048)
- param num_gpu: int | None = None#
The number of GPUs to use. On macOS it defaults to 1 to enable metal support, 0 to disable.
- param num_thread: int | None = None#
Sets the number of threads to use during computation. By default, Ollama will detect this for optimal performance. It is recommended to set this value to the number of physical CPU cores your system has (as opposed to the logical number of cores).
- param query_instruction: str = 'query: '#
Instruction used to embed the query.
- param repeat_last_n: int | None = None#
Sets how far back for the model to look back to prevent repetition. (Default: 64, 0 = disabled, -1 = num_ctx)
- param repeat_penalty: float | None = None#
Sets how strongly to penalize repetitions. A higher value (e.g., 1.5) will penalize repetitions more strongly, while a lower value (e.g., 0.9) will be more lenient. (Default: 1.1)
- param show_progress: bool = False#
Whether to show a tqdm progress bar. Must have tqdm installed.
- param stop: List[str] | None = None#
Sets the stop tokens to use.
- param temperature: float | None = None#
The temperature of the model. Increasing the temperature will make the model answer more creatively. (Default: 0.8)
- param tfs_z: float | None = None#
Tail free sampling is used to reduce the impact of less probable tokens from the output. A higher value (e.g., 2.0) will reduce the impact more, while a value of 1.0 disables this setting. (default: 1)
- param top_k: int | None = None#
Reduces the probability of generating nonsense. A higher value (e.g. 100) will give more diverse answers, while a lower value (e.g. 10) will be more conservative. (Default: 40)
- param top_p: float | None = None#
Works together with top-k. A higher value (e.g., 0.95) will lead to more diverse text, while a lower value (e.g., 0.5) will generate more focused and conservative text. (Default: 0.9)
- async aembed_documents(texts: list[str]) list[list[float]] #
Asynchronous Embed search docs.
- Parameters:
texts (list[str]) – List of text to embed.
- Returns:
List of embeddings.
- Return type:
list[list[float]]
- async aembed_query(text: str) list[float] #
Asynchronous Embed query text.
- Parameters:
text (str) – Text to embed.
- Returns:
Embedding.
- Return type:
list[float]
Examples using OllamaEmbeddings