forked from langchain-ai/langchainjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrate Rockset as a vector store (langchain-ai#3231)
* Integrate Rockset as a vector store * address comments * Mark Rockset as requiring optional dep * Fix lint * Fix build * Format --------- Co-authored-by: jacoblee93 <[email protected]>
- Loading branch information
1 parent
02f6662
commit d625ddd
Showing
14 changed files
with
675 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
sidebar_class_name: node-only | ||
--- | ||
|
||
import CodeBlock from "@theme/CodeBlock"; | ||
|
||
# Rockset | ||
|
||
[Rockset](https://rockset.com) is a real-time analyitics SQL database that runs in the cloud. | ||
Rockset provides vector search capabilities, in the form of [SQL functions](https://rockset.com/docs/vector-functions/#vector-distance-functions), to support AI applications that rely on text similarity. | ||
|
||
## Setup | ||
|
||
Install the rockset client. | ||
|
||
```bash | ||
yarn add @rockset/client | ||
``` | ||
|
||
### Usage | ||
|
||
import UsageExample from "@examples/indexes/vector_stores/rockset.ts"; | ||
|
||
Below is an example showcasing how to use OpenAI and Rockset to answer questions about a text file: | ||
|
||
<CodeBlock language="typescript">{UsageExample}</CodeBlock> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
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(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.