MongoDB LangGraph.js 와 통합할 수 있습니다. AI 에이전트 및 고급 RAG 애플리케이션을 빌드 . 이 페이지에서는 MongoDB LangGraph.js 통합에 대한 개요와 MongoDB 사용하여 LangGraph 워크플로에서 에이전트 상태 지속성 및 검색을 수행하는 방법을 설명합니다.
이 페이지의 모든 구성 요소를 사용하는 샘플 AI 에이전트 빌드 하려면 튜토리얼을 참조하세요.
참고
Python 통합에 대해서는 LangGraph를 참조하세요.
배경
LangGraph는 LangChain 에코시스템 내에서 AI 에이전트와 복잡한 다중 에이전트 워크플로를 구축하기 위해 설계된 전문 프레임워크입니다. 그래프는 LangGraph의 핵심 구성 요소로, 에이전트의 워크플로를 나타냅니다. MongoDB LangGraph 통합을 통해 다음 기능을 사용할 수 있습니다.
MongoDB LangGraph 체크포인터: 단기 기억을 제공하는 MongoDB에 LangGraph 에이전트의 상태 유지할 수 있습니다.
검색 도구: MongoDB LangChain 통합을 사용하면 LangGraph 워크플로에 대한 검색 도구를 신속하게 만들 수 있습니다.
LangGraph 애플리케이션을 MongoDB 와 통합하면 검색 기능과 에이전트 메모리를 단일 데이터베이스 에 통합하여 아키텍처를 간소화하고 운영 복잡성을 줄일 수 있습니다.
MongoDB LangGraph 체크포인터(단기 메모리)
MongoDB LangGraph 체크포인터를 사용하면 에이전트의 상태 MongoDB 에 유지하여 단기 기억을 구현 수 있습니다. 이 기능 LangGraph 에이전트를 위한 휴먼 인 루프(Human-in-Loop), 메모리, 시간 여행 및 내결함성을 활성화합니다.
이 구성 요소의 패키지 설치하려면 다음을 수행합니다.
npm install @langchain/langgraph-checkpoint-mongodb
사용법
import { MongoDBSaver } from "@langchain/langgraph-checkpoint-mongodb"; import { MongoClient } from "mongodb"; // Connect to your MongoDB cluster const client = new MongoClient("<connection-string>"); // Initialize the MongoDB checkpointer const checkpointer = new MongoDBSaver(client); // Instantiate the graph with the checkpointer const app = graph.compile(checkpointer);
검색 도구
LangGraph 워크플로의 도구로 리트리버를 원활하게 사용하여 MongoDB 에서 관련 데이터를 조회 할 수 있습니다.
사용법
MongoDB Vector Search 및 LangChain을 사용하여 기본 검색 도구를 만들려면 다음을 수행합니다.
import { MongoDBAtlasVectorSearch } from "@langchain/mongodb"; import { MongoClient } from "mongodb"; import { VoyageAIEmbeddings } from "@langchain/community/embeddings/voyage"; import { createRetrieverTool } from "langchain/tools/retriever"; // Instantiate the vector store const client = new MongoClient("<connection-string>"); const collection = client.db("<databaseName>").collection("<collectionName>"); const embeddingModel = new VoyageAIEmbeddings(); const vectorStore = new MongoDBAtlasVectorSearch(embeddingModel, { collection: collection, indexName: "vector_index", // Name of the index textKey: "text", // Name of the collection field containing the raw content embeddingKey: "embedding", // Name of the collection field containing the embedded text }); // Create a retriever tool const retriever = vectorStore.asRetriever(); const retrieverTool = createRetrieverTool( retriever, { name: "vector_search_retriever", // Tool name description: "Retrieve relevant documents from the collection" // Tool description }, ); LangGraph에 도구를 노드로 추가하려면:
도구를 노드로 변환합니다.
노드를 그래프에 추가합니다.
import { StateGraph } from "@langchain/langgraph"; import { ToolNode } from "@langchain/langgraph/prebuilt"; // Convert the retriever tool into a node const retrieverNode = new ToolNode([retrieverTool]); // Define the graph const workflow = new StateGraph(SomeGraphState) // Add the tool as a node in the graph .addNode("vector_search_retriever", retrieverNode); const graph = workflow.compile();