Skip to content

PGVector Vector Store node#

PGVector เป็น extension ของ Postgresql ใช้ node นี้เพื่อโต้ตอบกับตาราง PGVector ใน Postgresql database ของคุณ คุณสามารถใส่ documents เข้าไปใน vector table, ดึง documents จาก vector table, เรียกดู documents เพื่อส่งต่อไปยัง retriever ที่เชื่อมต่อกับ chain หรือเชื่อมต่อโดยตรงกับ agent ในฐานะ tool

ในหน้านี้ คุณจะพบ node parameters สำหรับ PGVector 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 }} จะถูกประมวลผลเป็นชื่อแรกเสมอ

Node usage patterns#

คุณสามารถใช้ PGVector Vector Store node ในรูปแบบต่อไปนี้

Use as a regular node to insert and retrieve documents#

คุณสามารถใช้ PGVector Vector Store เป็น node ปกติเพื่อ insert หรือ get documents รูปแบบนี้จะวาง PGVector Vector Store ไว้ใน flow การเชื่อมต่อปกติโดยไม่ต้องใช้ agent

คุณสามารถดูตัวอย่างได้ใน scenario 1 ของ template นี้ (template ใช้ Supabase Vector Store แต่รูปแบบเหมือนกัน)

Connect directly to an AI agent as a tool#

คุณสามารถเชื่อมต่อ PGVector Vector Store node โดยตรงกับ tool connector ของ AI agent เพื่อใช้ vector store เป็น resource เมื่อตอบคำถาม

ในกรณีนี้ การเชื่อมต่อจะเป็น: AI agent (tools connector) -> PGVector Vector Store node

Use a retriever to fetch documents#

คุณสามารถใช้ Vector Store Retriever node ร่วมกับ PGVector Vector Store node เพื่อดึง documents จาก PGVector 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) -> PGVector Vector Store

Use the Vector Store Question Answer Tool to answer questions#

อีกรูปแบบหนึ่งคือการใช้ Vector Store Question Answer Tool เพื่อสรุปผลลัพธ์และตอบคำถามจาก PGVector Vector Store node แทนที่จะเชื่อมต่อ PGVector Vector Store โดยตรงในฐานะ tool รูปแบบนี้จะใช้ tool ที่ออกแบบมาโดยเฉพาะเพื่อสรุปข้อมูลใน vector store

flow การเชื่อมต่อ (ตัวอย่างที่ลิงก์ใช้ Simple Vector Store แต่รูปแบบเหมือนกัน) ในกรณีนี้จะมีลักษณะดังนี้: AI agent (tools connector) -> Vector Store Question Answer Tool (Vector Store connector) -> Simple 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#

  • Table name: ป้อนชื่อตารางที่คุณต้องการ query
  • Prompt: ป้อนคำค้นหา (search query) ของคุณ
  • Limit: ป้อนตัวเลขเพื่อกำหนดจำนวนผลลัพธ์ที่จะดึงจาก vector store ตัวอย่างเช่น ตั้งค่าเป็น 10 เพื่อรับผลลัพธ์ที่ดีที่สุดสิบรายการ

Insert Documents parameters#

  • Table name: ป้อนชื่อตารางที่คุณต้องการ query

Retrieve Documents parameters (As Vector Store for Chain/Tool)#

  • Table name: ป้อนชื่อตารางที่คุณต้องการ query

Retrieve Documents (As Tool for AI Agent) parameters#

  • Name: ชื่อของ vector store
  • Description: อธิบายให้ LLM ทราบว่า tool นี้ทำอะไร คำอธิบายที่ดีและเฉพาะเจาะจงช่วยให้ LLM สร้างผลลัพธ์ที่คาดหวังได้บ่อยขึ้น
  • Table Name: ป้อนตาราง PGVector ที่จะใช้
  • Limit: ป้อนจำนวนผลลัพธ์ที่ต้องการดึงจาก vector store ตัวอย่างเช่น ตั้งค่าเป็น 10 เพื่อรับผลลัพธ์ที่ดีที่สุดสิบรายการ

Node options#

Collection#

วิธีแยก datasets ใน PGVector สิ่งนี้จะสร้างตารางและคอลัมน์แยกต่างหากเพื่อติดตามว่า vector ใดอยู่ใน collection ใด

  • Use Collection: เลือกว่าจะใช้ collection (เปิด) หรือไม่ (ปิด)
  • Collection Name: ป้อนชื่อ collection ที่คุณต้องการใช้
  • Collection Table Name: ป้อนชื่อตารางที่จะจัดเก็บข้อมูล collection

Column Names#

ตัวเลือกต่อไปนี้ระบุชื่อคอลัมน์ที่จะจัดเก็บ vectors และข้อมูลที่เกี่ยวข้อง:

  • ID Column Name
  • Vector Column Name
  • Content Column Name
  • Metadata Column Name

Metadata Filter#

Metadata Filter (ตัวกรอง Metadata)#

มีให้ใช้งานในโหมด Get Many เมื่อค้นหาข้อมูล ใช้ตัวเลือกนี้เพื่อจับคู่กับ metadata ที่เกี่ยวข้องกับเอกสาร

นี่คือการ query แบบ AND หากคุณระบุฟิลด์ตัวกรอง metadata มากกว่าหนึ่งฟิลด์ ทุกฟิลด์จะต้องตรงกันทั้งหมด

เมื่อแทรกข้อมูล metadata จะถูกตั้งค่าโดยใช้ document loader อ้างอิง Default Data Loader สำหรับข้อมูลเพิ่มเติมเกี่ยวกับการโหลดเอกสาร

Templates and examples#

HR & IT Helpdesk Chatbot with Audio Transcription

by Felipe Braga

View template details
Explore n8n Nodes in a Visual Reference Library

by I versus AI

View template details
📥 Transform Google Drive Documents into Vector Embeddings

by Alex Kim

View template details
Browse PGVector Vector Store integration templates, or search all templates

อ้างอิง เอกสาร PGVector ของ LangChain สำหรับข้อมูลเพิ่มเติมเกี่ยวกับบริการ

ดูเอกสาร 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