AstraDB is a document database with a highly performant vector index powered by Apache Cassandra and available as a managed service.

To use Astra as database -

  • Sign up for an AstraDB account. It is free to sign up and doesn’t require a credit card.
  • Create a database (this takes a couple of minutes to provision)
  • From the database overview page get the API Endpoint and generate an Application Token

Install AstraDB addon

npm install @llm-tools/embedjs-astradb

Usage

import { RAGApplicationBuilder } from '@llm-tools/embedjs';

import { OpenAiEmbeddings } from '@llm-tools/embedjs-openai';

import { AstraDb } from '@llm-tools/embedjs-astradb';

import { WebLoader } from '@llm-tools/embedjs-loader-web';



// set OPENAI_API_KEY in your env

process.env.OPENAI_API_KEY = "sk-xxx";



const app = await new RAGApplicationBuilder()

.setEmbeddingModel(new OpenAiEmbeddings())

.setModel(SIMPLE_MODELS.OPENAI_GPT4_O)

.setVectorDatabase(

    new AstraDb({

        endpoint: "<ASTRA_DB_API_ENDPOINT>",

        apiKey: "<ASTRA_DB_APP_TOKEN>",

        collectionName: "documents"

    })

)

.build();





//add data source and start query it

await app.addLoader(new WebLoader({ urlOrContent: 'https://www.forbes.com/profile/elon-musk' }));

await app.query('Tell me about Elon Musk');

If you can't find specific feature or run into issues, please feel free to reach out through the following channels.

Was this page helpful?