Skip to content

Groq

npm i llamaindex @llamaindex/groq

First, create an API key at the Groq Console. Then save it in your environment:

Terminal window
export GROQ_API_KEY=<your-api-key>

The initialize the Groq module.

import { Groq } from "@llamaindex/groq";
import { Settings } from "llamaindex";
Settings.llm = new Groq({
// If you do not wish to set your API key in the environment, you may
// configure your API key when you initialize the Groq class.
// apiKey: "<your-api-key>",
});

For this example, we will use a single document. In a real-world scenario, you would have multiple documents to index.

import { Document, VectorStoreIndex } from "llamaindex";
const document = new Document({ text: essay, id_: "essay" });
const index = await VectorStoreIndex.fromDocuments([document]);
const queryEngine = index.asQueryEngine();
const query = "What is the meaning of life?";
const results = await queryEngine.query({
query,
});
../../examples/models/groq.ts