Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Langchain ai Langchain FireworksEmbeddings

From Leeroopedia
Knowledge Sources
Domains Embeddings, Fireworks AI
Last Updated 2026-02-11 00:00 GMT

Overview

FireworksEmbeddings is a LangChain embeddings integration that generates text embeddings using the Fireworks AI inference API via the OpenAI client.

Description

FireworksEmbeddings extends both BaseModel (Pydantic) and Embeddings (langchain-core) to provide text embedding functionality through the Fireworks AI platform. It uses the OpenAI Python client configured with the Fireworks AI base URL (https://api.fireworks.ai/inference/v1) to generate embeddings. The default model is nomic-ai/nomic-embed-text-v1.5. The API key is automatically read from the FIREWORKS_API_KEY environment variable.

Usage

Import this class when you need to generate text embeddings using Fireworks AI models for semantic search, RAG pipelines, or other embedding-based workflows.

Code Reference

Source Location

  • Repository: Langchain_ai_Langchain
  • File: libs/partners/fireworks/langchain_fireworks/embeddings.py
  • Lines: 1-108

Signature

class FireworksEmbeddings(BaseModel, Embeddings):
    client: OpenAI = Field(default=None, exclude=True)
    fireworks_api_key: SecretStr = Field(alias="api_key", ...)
    model: str = "nomic-ai/nomic-embed-text-v1.5"

    def embed_documents(self, texts: list[str]) -> list[list[float]]: ...
    def embed_query(self, text: str) -> list[float]: ...

Import

from langchain_fireworks import FireworksEmbeddings

I/O Contract

Inputs

Name Type Required Description
model str No Name of the Fireworks model to use. Default: "nomic-ai/nomic-embed-text-v1.5".
fireworks_api_key SecretStr No Fireworks API key. Automatically read from FIREWORKS_API_KEY env var. Also accepts api_key alias.
texts list[str] Yes (for embed_documents) List of texts to embed.
text str Yes (for embed_query) Single text to embed.

Outputs

Name Type Description
embed_documents return list[list[float]] List of embedding vectors, one per input text.
embed_query return list[float] Single embedding vector for the query text.

Usage Examples

Basic Usage

from langchain_fireworks import FireworksEmbeddings

model = FireworksEmbeddings(
    model="nomic-ai/nomic-embed-text-v1.5"
    # Uses FIREWORKS_API_KEY env var by default
)

# Embed multiple documents
vectors = model.embed_documents(["hello", "goodbye"])
print(len(vectors))       # 2
print(vectors[0][:3])     # First 3 coordinates

# Embed a single query
vector = model.embed_query("The meaning of life is 42")
print(vector[:3])

Related Pages

  • Requires langchain-fireworks and openai packages
  • Uses OpenAI client with Fireworks AI base URL

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment