Skip to main content

Rockset

Rockset is a real-time analyitics SQL database that runs in the cloud. Rockset provides vector search capabilities, in the form of SQL functions, to support AI applications that rely on text similarity.

Setup

Install the rockset client.

yarn add @rockset/client

Usage

Below is an example showcasing how to use OpenAI and Rockset to answer questions about a text file:

import * as rockset from "@rockset/client";
import { ChatOpenAI } from "langchain/chat_models/openai";
import { RetrievalQAChain } from "langchain/chains";
import { OpenAIEmbeddings } from "langchain/embeddings/openai";
import { RocksetStore } from "langchain/vectorstores/rockset";
import { RecursiveCharacterTextSplitter } from "langchain/text_splitter";
import { readFileSync } from "fs";

export const run = async () => {
const store = await RocksetStore.withNewCollection(new OpenAIEmbeddings(), {
client: rockset.default.default(
process.env.ROCKSET_API_KEY ?? "",
`https://api.${process.env.ROCKSET_API_REGION ?? "usw2a1"}.rockset.com`
),
collectionName: "langchain_demo",
});

const model = new ChatOpenAI({ modelName: "gpt-3.5-turbo" });
const chain = RetrievalQAChain.fromLLM(model, store.asRetriever());
const text = readFileSync("state_of_the_union.txt", "utf8");
const docs = await new RecursiveCharacterTextSplitter().createDocuments([
text,
]);

await store.addDocuments(docs);
const response = await chain.call({
query: "What is America's role in Ukraine?",
});
console.log(response.text);
await store.destroy();
};

API Reference: