FireworksEmbeddings
This will help you get started with FireworksEmbeddings embedding
models using LangChain. For detailed
documentation on FireworksEmbeddings
features and configuration
options, please refer to the API
reference.
Overviewβ
Integration detailsβ
Class | Package | Local | Py support | Package downloads | Package latest |
---|---|---|---|---|---|
FireworksEmbeddings | @langchain/community | β | β |
Setupβ
To access Fireworks embedding models youβll need to create a Fireworks
account, get an API key, and install the @langchain/community
integration package.
Credentialsβ
Head to fireworks.ai to sign up to Fireworks
and generate an API key. Once youβve done this set the
FIREWORKS_API_KEY
environment variable:
export FIREWORKS_API_KEY="your-api-key"
If you want to get automated tracing of your model calls you can also set your LangSmith API key by uncommenting below:
# export LANGCHAIN_TRACING_V2="true"
# export LANGCHAIN_API_KEY="your-api-key"
Installationβ
The LangChain FireworksEmbeddings
integration lives in the
@langchain/community
package:
- npm
- yarn
- pnpm
npm i @langchain/community @langchain/core
yarn add @langchain/community @langchain/core
pnpm add @langchain/community @langchain/core
Instantiationβ
Now we can instantiate our model object and generate chat completions:
import { FireworksEmbeddings } from "@langchain/community/embeddings/fireworks";
const embeddings = new FireworksEmbeddings({
modelName: "nomic-ai/nomic-embed-text-v1.5",
});
Indexing and Retrievalβ
Embedding models are often used in retrieval-augmented generation (RAG) flows, both as part of indexing data as well as later retrieving it. For more detailed instructions, please see our RAG tutorials under the working with external knowledge tutorials.
Below, see how to index and retrieve data using the embeddings
object
we initialized above. In this example, we will index and retrieve a
sample document using the demo
MemoryVectorStore
.
// Create a vector store with a sample text
import { MemoryVectorStore } from "langchain/vectorstores/memory";
const text =
"LangChain is the framework for building context-aware reasoning applications";
const vectorstore = await MemoryVectorStore.fromDocuments(
[{ pageContent: text, metadata: {} }],
embeddings
);
// Use the vector store as a retriever that returns a single document
const retriever = vectorstore.asRetriever(1);
// Retrieve the most similar text
const retrievedDocuments = await retriever.invoke("What is LangChain?");
retrievedDocuments[0].pageContent;
"LangChain is the framework for building context-aware reasoning applications"
Direct Usageβ
Under the hood, the vectorstore and retriever implementations are
calling embeddings.embedDocument(...)
and embeddings.embedQuery(...)
to create embeddings for the text(s) used in fromDocuments
and the
retrieverβs invoke
operations, respectively.
You can directly call these methods to get embeddings for your own use cases.
Embed single textsβ
You can embed queries for search with embedQuery
. This generates a
vector representation specific to the query:
const singleVector = await embeddings.embedQuery(text);
console.log(singleVector.slice(0, 100));
[
0.01666259765625, 0.011688232421875, -0.1181640625,
-0.10205078125, 0.05438232421875, -0.08905029296875,
-0.018096923828125, 0.00952911376953125, -0.08056640625,
-0.0283050537109375, -0.01512908935546875, 0.0312042236328125,
0.08197021484375, 0.022552490234375, 0.0012683868408203125,
0.0133056640625, -0.04327392578125, -0.004322052001953125,
-0.02410888671875, -0.0012350082397460938, -0.04632568359375,
0.02996826171875, -0.0134124755859375, -0.037811279296875,
0.07672119140625, 0.021759033203125, 0.0179290771484375,
-0.0002741813659667969, -0.0582275390625, -0.0224456787109375,
0.0027675628662109375, -0.017425537109375, -0.01520538330078125,
-0.01146697998046875, -0.055267333984375, -0.083984375,
0.056793212890625, -0.003383636474609375, -0.034271240234375,
0.05108642578125, -0.01018524169921875, 0.0462646484375,
0.0012178421020507812, 0.005779266357421875, 0.0684814453125,
0.00797271728515625, -0.0176544189453125, 0.00257110595703125,
0.059539794921875, -0.06573486328125, -0.075439453125,
-0.0247344970703125, -0.0276947021484375, 0.003940582275390625,
0.02630615234375, 0.0660400390625, 0.0157470703125,
0.033050537109375, -0.0478515625, -0.03338623046875,
0.050384521484375, 0.07757568359375, -0.045166015625,
0.07586669921875, 0.0021915435791015625, 0.0237579345703125,
-0.052703857421875, 0.05023193359375, -0.0274810791015625,
-0.0025081634521484375, 0.019287109375, -0.03802490234375,
0.0216217041015625, 0.025360107421875, -0.04443359375,
-0.029205322265625, -0.002414703369140625, 0.027130126953125,
0.028961181640625, 0.078857421875, -0.0009660720825195312,
0.017608642578125, 0.05755615234375, -0.0285797119140625,
0.0039215087890625, -0.006908416748046875, -0.05364990234375,
-0.01342010498046875, -0.0247802734375, 0.08331298828125,
0.032928466796875, 0.00543975830078125, -0.0168304443359375,
-0.050018310546875, -0.05908203125, 0.031951904296875,
-0.0200347900390625, 0.019134521484375, -0.018035888671875,
-0.01178741455078125
]
Embed multiple textsβ
You can embed multiple texts for indexing with embedDocuments
. The
internals used for this method may (but do not have to) differ from
embedding queries:
const text2 =
"LangGraph is a library for building stateful, multi-actor applications with LLMs";
const vectors = await embeddings.embedDocuments([text, text2]);
console.log(vectors[0].slice(0, 100));
console.log(vectors[1].slice(0, 100));
[
0.016632080078125, 0.01165008544921875, -0.1181640625,
-0.10186767578125, 0.05438232421875, -0.08905029296875,
-0.0180511474609375, 0.00957489013671875, -0.08056640625,
-0.0283203125, -0.0151214599609375, 0.0311279296875,
0.08184814453125, 0.0225982666015625, 0.0012750625610351562,
0.01336669921875, -0.043365478515625, -0.004322052001953125,
-0.02410888671875, -0.0012559890747070312, -0.046356201171875,
0.0298919677734375, -0.013458251953125, -0.03765869140625,
0.07672119140625, 0.0217132568359375, 0.0179290771484375,
-0.0002269744873046875, -0.0582275390625, -0.0224609375,
0.002834320068359375, -0.0174407958984375, -0.01512908935546875,
-0.01146697998046875, -0.055206298828125, -0.08404541015625,
0.0567626953125, -0.0033092498779296875, -0.034271240234375,
0.05108642578125, -0.010101318359375, 0.046173095703125,
0.0011806488037109375, 0.005706787109375, 0.06854248046875,
0.0079193115234375, -0.0176239013671875, 0.002552032470703125,
0.059539794921875, -0.06573486328125, -0.07537841796875,
-0.02484130859375, -0.027740478515625, 0.003925323486328125,
0.0263671875, 0.0660400390625, 0.0156402587890625,
0.033050537109375, -0.047821044921875, -0.0333251953125,
0.050445556640625, 0.07757568359375, -0.045257568359375,
0.07586669921875, 0.0021724700927734375, 0.0237274169921875,
-0.052703857421875, 0.050323486328125, -0.0274658203125,
-0.0024662017822265625, 0.0194244384765625, -0.03802490234375,
0.02166748046875, 0.025360107421875, -0.044464111328125,
-0.0292816162109375, -0.0025119781494140625, 0.0271148681640625,
0.028961181640625, 0.078857421875, -0.0008907318115234375,
0.017669677734375, 0.0576171875, -0.0285797119140625,
0.0039825439453125, -0.00687408447265625, -0.0535888671875,
-0.0134735107421875, -0.0247650146484375, 0.0831298828125,
0.032989501953125, 0.005443572998046875, -0.0167999267578125,
-0.050018310546875, -0.059051513671875, 0.0318603515625,
-0.0200958251953125, 0.0191192626953125, -0.0180206298828125,
-0.01175689697265625
]
[
-0.02667236328125, 0.036651611328125, -0.1630859375,
-0.0904541015625, -0.022430419921875, -0.095458984375,
-0.037628173828125, 0.00473785400390625, -0.046051025390625,
0.0109710693359375, 0.0113525390625, 0.0254364013671875,
0.09368896484375, 0.0144195556640625, -0.007564544677734375,
-0.0014705657958984375, -0.0007691383361816406, -0.015716552734375,
-0.0242156982421875, -0.024871826171875, 0.00885009765625,
0.0012922286987304688, 0.023712158203125, -0.054595947265625,
0.06329345703125, 0.0289306640625, 0.0233612060546875,
-0.0374755859375, -0.0489501953125, -0.029510498046875,
0.0173492431640625, 0.0171356201171875, -0.01629638671875,
-0.0352783203125, -0.039398193359375, -0.11138916015625,
0.0296783447265625, -0.01467132568359375, 0.0009188652038574219,
0.048187255859375, -0.010650634765625, 0.03125,
0.005214691162109375, -0.015869140625, 0.06939697265625,
-0.0428466796875, 0.0266571044921875, 0.044189453125,
0.049957275390625, -0.054290771484375, 0.0107574462890625,
-0.03265380859375, -0.0109100341796875, -0.0144805908203125,
0.03936767578125, 0.07989501953125, -0.056976318359375,
0.0308380126953125, -0.035125732421875, -0.038848876953125,
0.10748291015625, 0.01129150390625, -0.0665283203125,
0.09710693359375, 0.03143310546875, -0.0104522705078125,
-0.062469482421875, 0.021148681640625, -0.00970458984375,
-0.06756591796875, 0.01019287109375, 0.00433349609375,
0.032928466796875, 0.020233154296875, -0.01336669921875,
-0.015472412109375, -0.0175933837890625, -0.0142364501953125,
-0.007450103759765625, 0.03759765625, 0.003551483154296875,
0.0069580078125, 0.042266845703125, -0.007488250732421875,
0.01922607421875, 0.007080078125, -0.0255889892578125,
-0.007686614990234375, -0.0848388671875, 0.058563232421875,
0.021148681640625, 0.034393310546875, 0.01087188720703125,
-0.0196380615234375, -0.09515380859375, 0.0054931640625,
-0.012481689453125, 0.003322601318359375, -0.019683837890625,
-0.0307159423828125
]
API referenceβ
For detailed documentation of all FireworksEmbeddings features and configurations head to the API reference: https://api.js.langchain.com/classes/langchain_community_embeddings_fireworks.FireworksEmbeddings.html
Relatedβ
- Embedding model conceptual guide
- Embedding model how-to guides