From 67422c9566d25db0acbc522de3ab7704cd199a55 Mon Sep 17 00:00:00 2001 From: Harrison Chase Date: Wed, 1 Mar 2023 07:50:29 -0800 Subject: [PATCH] bump version (#177) * bump version * cr --- .../agents/agent_toolkits/vectorstore.md | 50 +++++++++++++++++++ langchain/package.json | 2 +- 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 docs/docs/modules/agents/agent_toolkits/vectorstore.md diff --git a/docs/docs/modules/agents/agent_toolkits/vectorstore.md b/docs/docs/modules/agents/agent_toolkits/vectorstore.md new file mode 100644 index 000000000000..5f03f1e90434 --- /dev/null +++ b/docs/docs/modules/agents/agent_toolkits/vectorstore.md @@ -0,0 +1,50 @@ +# VectorStore Agent Toolkit + +This example shows how to load and use an agent with a vectorstore toolkit. + +```typescript +import { OpenAI } from "langchain"; +import { HNSWLib } from "langchain/vectorstores"; +import { OpenAIEmbeddings } from "langchain/embeddings"; +import { RecursiveCharacterTextSplitter } from "langchain/text_splitter"; +import * as fs from "fs"; +import { + VectorStoreToolkit, + createVectorStoreAgent, + VectorStoreInfo, +} from "langchain/agents"; + +export const run = async () => { + const model = new OpenAI({ temperature: 0 }); + /* Load in the file we want to do question answering over */ + const text = fs.readFileSync("state_of_the_union.txt", "utf8"); + /* Split the text into chunks */ + const textSplitter = new RecursiveCharacterTextSplitter({ chunkSize: 1000 }); + const docs = await textSplitter.createDocuments([text]); + /* Create the vectorstore */ + const vectorStore = await HNSWLib.fromDocuments(docs, new OpenAIEmbeddings()); + + /* Create the agent */ + const vectorStoreInfo: VectorStoreInfo = { + name: "state_of_union_address", + description: "the most recent state of the Union address", + vectorStore, + }; + + const toolkit = new VectorStoreToolkit(vectorStoreInfo, model); + const agent = createVectorStoreAgent(model, toolkit); + + const input = + "What did biden say about Ketanji Brown Jackson is the state of the union address?"; + console.log(`Executing: ${input}`); + const result = await agent.call({ input }); + console.log(`Got output ${result.output}`); + console.log( + `Got intermediate steps ${JSON.stringify( + result.intermediateSteps, + null, + 2 + )}` + ); +}; +``` diff --git a/langchain/package.json b/langchain/package.json index f843a57582b7..979b99b3ada5 100644 --- a/langchain/package.json +++ b/langchain/package.json @@ -1,6 +1,6 @@ { "name": "langchain", - "version": "0.0.16", + "version": "0.0.17", "description": "Typescript bindings for langchain", "type": "module", "main": "./index.js",