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:

  1. Download a llamafile.

  2. Make the downloaded file executable: chmod +x path/to/model.llamafile

  3. 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 if the input data cannot be parsed to form a valid model.

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]]

embed_query(text: str) List[float][source]#

Embed a query using a llamafile server running at self.base_url. llamafile server should be started in a separate process before invoking this method.

Parameters:

text (str) – The text to embed.

Returns:

Embeddings for the text.

Return type:

List[float]

Examples using LlamafileEmbeddings