LlamafileEmbeddings#
- class langchain_community.embeddings.llamafile.LlamafileEmbeddings[source]#
Bases:
BaseModel
,Embeddings
Llamafile lets you distribute and run large language models with a single file.
To get started, see: Mozilla-Ocho/llamafile
To use this class, you will need to first:
Download a llamafile.
Make the downloaded file executable: chmod +x path/to/model.llamafile
Start the llamafile in server mode with embeddings enabled:
./path/to/model.llamafile –server –nobrowser –embedding
Example
from langchain_community.embeddings import LlamafileEmbeddings embedder = LlamafileEmbeddings() doc_embeddings = embedder.embed_documents( [ "Alpha is the first letter of the Greek alphabet", "Beta is the second letter of the Greek alphabet", ] ) query_embedding = embedder.embed_query( "What is the second letter of the 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:8080'#
Base url where the llamafile server is listening.
- param request_timeout: int | None = None#
Timeout for server requests
- 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]
- embed_documents(texts: List[str]) List[List[float]] [source]#
Embed documents using a llamafile server running at self.base_url. llamafile server should be started in a separate process before invoking this method.
- Parameters:
texts (List[str]) – The list of texts to embed.
- Returns:
List of embeddings, one for each text.
- Return type:
List[List[float]]
Examples using LlamafileEmbeddings