VectorStoreToolkit 통합
VectorStoreToolkit 통합 (VectorStoreToolkit integration)
LangChain JavaScript로 VectorStoreToolkit 툴과 통합해요.
VectorStoreToolkit 툴킷 시작을 도와드려요. 모든 VectorStoreToolkit 기능과 구성에 대한 자세한 문서는 API reference를 참고하세요.
VectorStoreToolkit은 벡터 스토어를 받아서 호출 가능한 툴로 변환한 뒤, LLM·에이전트 등에 전달할 수 있게 하는 툴킷이에요.
설정 (Setup)
개별 툴 실행의 자동 추적을 받으려면 아래 주석을 해제해 LangSmith API 키를 설정할 수도 있어요:
process.env.LANGSMITH_TRACING="true"
process.env.LANGSMITH_API_KEY="your-api-key"
설치 (Installation)
이 툴킷은 langchain 패키지에 있어요:
yarn add langchain @langchain/core
pnpm add langchain @langchain/core
인스턴스화 (Instantiation)
이제 툴킷을 인스턴스화할 수 있어요. 먼저 툴킷에 사용할 LLM을 정의해야 해요.
// @lc-docs-hide-cell
import { ChatOpenAI } from "@langchain/openai";
const llm = new ChatOpenAI({
model: "gpt-5.4-mini",
temperature: 0,
})
import { VectorStoreToolkit, VectorStoreInfo } from "@langchain/classic/agents/toolkits"
import { OpenAIEmbeddings } from "@langchain/openai"
import { MemoryVectorStore } from "@langchain/classic/vectorstores/memory"
import { RecursiveCharacterTextSplitter } from "@langchain/textsplitters";
import fs from "fs";
// Load a text file to use as our data source.
const text = fs.readFileSync("../../../../../examples/state_of_the_union.txt", "utf8");
// Split the text into chunks before inserting to our store
const textSplitter = new RecursiveCharacterTextSplitter({ chunkSize: 1000 });
const docs = await textSplitter.createDocuments([text]);
const vectorStore = await MemoryVectorStore.fromDocuments(docs, new OpenAIEmbeddings());
const vectorStoreInfo: VectorStoreInfo = {
name: "state_of_union_address",
description: "the most recent state of the Union address",
vectorStore,
};
const toolkit = new VectorStoreToolkit(vectorStoreInfo, llm);
툴 (Tools)
여기서 벡터 스토어가 툴로 변환되는 것을 볼 수 있어요:
const tools = toolkit.getTools();
console.log(tools.map((tool) => ({
name: tool.name,
description: tool.description,
})))
[
{
name: 'state_of_union_address',
description: 'Useful for when you need to answer questions about state_of_union_address. Whenever you need information about the most recent state of the Union address you should ALWAYS use this. Input should be a fully formed question.'
}
]
에이전트 내에서 사용 (Use within an agent)
먼저 LangGraph가 설치되어 있는지 확인하세요:
yarn add @langchain/langgraph
pnpm add @langchain/langgraph
그런 다음 에이전트를 인스턴스화하세요:
import { createAgent } from "@langchain/classic"
const agentExecutor = createAgent({ llm, tools });
const exampleQuery = "What did biden say about Ketanji Brown Jackson is the state of the union address?"
const stream = await agentExecutor.streamEvents(
{ messages: [["user", exampleQuery]] },
{ version: "v3" },
);
for await (const snapshot of stream.values) {
const lastMsg = snapshot.messages[snapshot.messages.length - 1];
if (lastMsg.tool_calls?.length) {
console.dir(lastMsg.tool_calls, { depth: null });
} else if (lastMsg.content) {
console.log(lastMsg.content);
}
}
[
{
name: 'state_of_union_address',
args: {
input: 'What did Biden say about Ketanji Brown Jackson in the State of the Union address?'
},
type: 'tool_call',
id: 'call_glJSWLNrftKHa92A6j8x4jhd'
}
]
In the State of the Union address, Biden mentioned that he nominated Circuit Court of Appeals Judge Ketanji Brown Jackson...
API reference
모든 VectorStoreToolkit 기능과 구성에 대한 자세한 문서는 API reference를 참고하세요.
출처: 문서
본문
VectorStoreToolkit은 벡터 스토어를 호출 가능한 툴로 변환하는 툴킷이에요. 텍스트를 청킹해 MemoryVectorStore에 저장하고, VectorStoreInfo로 이름·설명을 붙인 뒤 VectorStoreToolkit(vectorStoreInfo, llm)으로 구성하면 getTools()가 벡터 검색 툴을 반환해요. createAgent에 연결해 검색 기반 질의응답 에이전트를 만들 수 있어요.