MongoDB Atlas Vector Store node#
MongoDB Atlas Vector Search เป็นฟีเจอร์ของ MongoDB Atlas ที่ช่วยให้ผู้ใช้สามารถจัดเก็บและ query vector embeddings ได้ ใช้ node นี้เพื่อโต้ตอบกับ Vector Search indexes ใน MongoDB Atlas collections ของคุณ คุณสามารถ insert documents, retrieve documents และใช้ vector store ใน chains หรือเป็น tool สำหรับ agents
ในหน้านี้ คุณจะพบ node parameters สำหรับ MongoDB Atlas Vector Store node และลิงก์ไปยังแหล่งข้อมูลเพิ่มเติม
Credentials
คุณสามารถดูข้อมูล authentication สำหรับ node นี้ได้ ที่นี่
Parameter resolution in sub-nodes (การประมวลผล Parameter ใน sub-nodes)
Sub-nodes มีพฤติกรรมแตกต่างจาก node อื่นๆ เมื่อประมวลผลหลายรายการโดยใช้ expression
Node ส่วนใหญ่ รวมถึง root node จะรับ input กี่รายการก็ได้ ประมวลผลรายการเหล่านี้ และส่ง output ออกมา คุณสามารถใช้ expression เพื่ออ้างอิงถึง input item และ node จะประมวลผล expression สำหรับแต่ละ item ตามลำดับ ตัวอย่างเช่น หากมี input เป็นค่า name
ห้ารายการ expression {{ $json.name }}
จะถูกประมวลผลเป็นแต่ละชื่อตามลำดับ
ใน sub-nodes expression จะถูกประมวลผลเป็น item แรกเสมอ ตัวอย่างเช่น หากมี input เป็นค่า name
ห้ารายการ expression {{ $json.name }}
จะถูกประมวลผลเป็นชื่อแรกเสมอ
Prerequisites#
ก่อนใช้ node นี้ ให้สร้าง Vector Search index ใน MongoDB Atlas collection ของคุณ ทำตามขั้นตอนเหล่านี้เพื่อสร้าง:
-
เข้าสู่ระบบ MongoDB Atlas dashboard
-
เลือก organization และ project ของคุณ
- ค้นหาส่วน "Search & Vector Search"
- เลือก cluster ของคุณและคลิก "Go to search"
- คลิก "Create Search Index"
-
เลือกโหมด "Vector Search" และใช้ visual หรือ JSON editors ตัวอย่างเช่น:
1 2 3 4 5 6 7 8 9 10
{ "fields": [ { "type": "vector", "path": "<field-name>", "numDimensions": 1536, // any other value "similarity": "<similarity-function>" } ] }
-
ปรับค่า "dimensions" ตาม embedding model ของคุณ (ตัวอย่างเช่น
1536
สำหรับtext-embedding-small-3
ของ OpenAI) - ตั้งชื่อ index ของคุณและสร้าง
ตรวจสอบให้แน่ใจว่าได้จดค่าต่อไปนี้ซึ่งจำเป็นเมื่อกำหนดค่า node:
- Collection name
- Vector index name
- Field names สำหรับ embeddings และ metadata
Node usage patterns#
คุณสามารถใช้ MongoDB Atlas Vector Store node ในรูปแบบต่อไปนี้:
Use as a regular node to insert and retrieve documents#
คุณสามารถใช้ MongoDB Atlas Vector Store เป็น node ปกติเพื่อ insert หรือ get documents รูปแบบนี้จะวาง MongoDB Atlas Vector Store ไว้ใน flow การเชื่อมต่อปกติโดยไม่ต้องใช้ agent
คุณสามารถดูตัวอย่างได้ใน scenario 1 ของ template นี้ (template ใช้ Supabase Vector Store แต่รูปแบบเหมือนกัน)
Connect directly to an AI agent as a tool#
คุณสามารถเชื่อมต่อ MongoDB Atlas Vector Store node โดยตรงกับ tool connector ของ AI agent เพื่อใช้ vector store เป็น resource เมื่อตอบคำถาม
ในกรณีนี้ การเชื่อมต่อจะเป็น: AI agent (tools connector) -> MongoDB Atlas Vector Store node
Use a retriever to fetch documents#
คุณสามารถใช้ Vector Store Retriever node ร่วมกับ MongoDB Atlas Vector Store node เพื่อดึง documents จาก MongoDB Atlas Vector Store node ซึ่งมักใช้กับ Question and Answer Chain node เพื่อดึง documents จาก vector store ที่ตรงกับ input ของ chat ที่กำหนด
ตัวอย่างของ flow การเชื่อมต่อ (ตัวอย่างที่ลิงก์ใช้ Pinecone แต่รูปแบบเหมือนกัน) จะเป็น: Question and Answer Chain (Retriever connector) -> Vector Store Retriever (Vector Store connector) -> MongoDB Atlas Vector Store
Use the Vector Store Question Answer Tool to answer questions#
อีกรูปแบบหนึ่งคือการใช้ Vector Store Question Answer Tool เพื่อสรุปผลลัพธ์และตอบคำถามจาก MongoDB Atlas Vector Store node แทนที่จะเชื่อมต่อ MongoDB Atlas Vector Store โดยตรงในฐานะ tool รูปแบบนี้จะใช้ tool ที่ออกแบบมาโดยเฉพาะเพื่อสรุปข้อมูลใน vector store
flow การเชื่อมต่อ (ตัวอย่างที่ลิงก์ใช้ In-Memory Vector Store แต่รูปแบบเหมือนกัน) ในกรณีนี้จะมีลักษณะดังนี้: AI agent (tools connector) -> Vector Store Question Answer Tool (Vector Store connector) -> In-Memory Vector store
Node parameters#
Operation Mode (โหมดการทำงาน)#
Vector Store node นี้มีสี่โหมด: Get Many, Insert Documents, Retrieve Documents (As Vector Store for Chain/Tool), และ Retrieve Documents (As Tool for AI Agent) โหมดที่คุณเลือกจะกำหนดการดำเนินการที่คุณสามารถทำได้ด้วย node และ input/output ที่มีให้ใช้งาน
Get Many (ดึงข้อมูลหลายรายการ)#
ในโหมดนี้ คุณสามารถดึงเอกสารหลายรายการจาก vector database ของคุณโดยการระบุ prompt ตัว prompt จะถูกแปลงเป็น embedding และใช้สำหรับการค้นหาความคล้ายคลึง (similarity search) node จะส่งคืนเอกสารที่คล้ายกับ prompt มากที่สุดพร้อมกับคะแนนความคล้ายคลึง (similarity score) ซึ่งมีประโยชน์หากคุณต้องการดึงรายการเอกสารที่คล้ายกันและส่งต่อไปยัง agent เพื่อใช้เป็น context เพิ่มเติม
Insert Documents (แทรกเอกสาร)#
ใช้โหมด Insert Documents เพื่อแทรกเอกสารใหม่เข้าไปใน vector database ของคุณ
Retrieve Documents (As Vector Store for Chain/Tool) (ดึงเอกสาร - เป็น Vector Store สำหรับ Chain/Tool)#
ใช้โหมด Retrieve Documents (As Vector Store for Chain/Tool) กับ vector-store retriever เพื่อดึงเอกสารจาก vector database และส่งต่อไปยัง retriever ที่เชื่อมต่อกับ chain ในโหมดนี้ คุณต้องเชื่อมต่อ node เข้ากับ retriever node หรือ root node
Retrieve Documents (As Tool for AI Agent) (ดึงเอกสาร - เป็น Tool สำหรับ AI Agent)#
ใช้โหมด Retrieve Documents (As Tool for AI Agent) เพื่อใช้ vector store เป็น tool resource ในการตอบคำถาม เมื่อสร้างคำตอบ agent จะใช้ vector store เมื่อชื่อและคำอธิบายของ vector store ตรงกับรายละเอียดของคำถาม
Get Many parameters#
- Mongo Collection: ป้อนชื่อ MongoDB collection ที่จะใช้
- Vector Index Name: ป้อนชื่อ Vector Search index ใน MongoDB Atlas collection ของคุณ
- Embedding Field: ป้อนชื่อ field ใน documents ของคุณที่มี vector embeddings
- Metadata Field: ป้อนชื่อ field ใน documents ของคุณที่มี text metadata
Insert Documents parameters#
- Mongo Collection: ป้อนชื่อ MongoDB collection ที่จะใช้
- Vector Index Name: ป้อนชื่อ Vector Search index ใน MongoDB Atlas collection ของคุณ
- Embedding Field: ป้อนชื่อ field ใน documents ของคุณที่มี vector embeddings
- Metadata Field: ป้อนชื่อ field ใน documents ของคุณที่มี text metadata
Retrieve Documents parameters (As Vector Store for Chain/Tool)#
- Mongo Collection: ป้อนชื่อ MongoDB collection ที่จะใช้
- Vector Index Name: ป้อนชื่อ Vector Search index ใน MongoDB Atlas collection ของคุณ
- Embedding Field: ป้อนชื่อ field ใน documents ของคุณที่มี vector embeddings
- Metadata Field: ป้อนชื่อ field ใน documents ของคุณที่มี text metadata
Retrieve Documents (As Tool for AI Agent) parameters#
- Name: ชื่อของ vector store
- Description: อธิบายให้ LLM ทราบว่า tool นี้ทำอะไร คำอธิบายที่ดีและเฉพาะเจาะจงช่วยให้ LLM สร้างผลลัพธ์ที่คาดหวังได้บ่อยขึ้น
- Mongo Collection: ป้อนชื่อ MongoDB collection ที่จะใช้
- Vector Index Name: ป้อนชื่อ Vector Search index ใน MongoDB Atlas collection ของคุณ
- Limit: ป้อนจำนวนผลลัพธ์ที่ต้องการดึงจาก vector store ตัวอย่างเช่น ตั้งค่าเป็น
10
เพื่อรับผลลัพธ์ที่ดีที่สุดสิบรายการ
Node options#
Options#
- Metadata Filter: กรองผลลัพธ์ตาม metadata
Templates and examples#
Related resources#
อ้างอิง:
- เอกสาร MongoDB Atlas Vector Search ของ LangChain สำหรับข้อมูลเพิ่มเติมเกี่ยวกับบริการ
- เอกสาร MongoDB Atlas Vector Search สำหรับข้อมูลเพิ่มเติมเกี่ยวกับ MongoDB Atlas Vector Search
ดูเอกสาร Advanced AI ของ n8n
Self-hosted AI Starter Kit#
เพิ่งเริ่มต้นทำงานกับ AI และใช้ n8n แบบ Self-hosted ใช่ไหม? ลองใช้ self-hosted AI Starter Kit ของ n8n เพื่อเริ่มต้นสร้าง Proof-of-Concept หรือ Playground สำหรับทดลอง โดยใช้ Ollama, Qdrant และ PostgreSQL