🦙อย่างเป็นทางการ

การเชื่อมต่อ LlamaIndex

Native retriever สำหรับ LlamaIndex Query Engine พร้อม Streaming และ Hybrid Search

01ภาพรวม 60 วินาที

SeiznRetriever ใช้งาน LlamaIndex BaseRetriever Interface ทำให้ใช้งานร่วมกับ LlamaIndex Query Engine และ Pipeline ทั้งหมดได้

  • เชื่อมต่อกับ LlamaIndex Query Engine แบบ Native
  • รองรับ Streaming Response ได้ทันที
  • ใช้งานร่วมกับ LlamaIndex Node Postprocessor ได้

02การติดตั้ง

ติดตั้ง Seizn SDK ควบคู่กับ LlamaIndex

Installationbash
# TypeScript / JavaScript
npm install seizn llamaindex

# Python
pip install seizn llama-index

03ตัวอย่าง 5 นาที

สร้าง Query Engine ด้วย SeiznRetriever สำหรับแอปพลิเคชัน RAG ของคุณ

TypeScripttypescript
import { SeiznRetriever } from 'seizn/llamaindex';
import { OpenAI } from 'llamaindex';
import { VectorStoreIndex, RetrieverQueryEngine } from 'llamaindex';

// Initialize the Seizn retriever
const retriever = new SeiznRetriever({
  apiKey: process.env.SEIZN_API_KEY,
  dataset: 'my-docs',
  topK: 5,
  threshold: 0.7,
});

// Create a query engine with the retriever
const llm = new OpenAI({ model: 'gpt-4' });
const queryEngine = new RetrieverQueryEngine(retriever, llm);

// Query your documents
const response = await queryEngine.query(
  'How do I configure rate limiting?'
);

console.log(response.response);
// Access the trace for debugging
console.log('Trace:', response.metadata?.seiznTrace);
Pythonpython
import os
from seizn.llamaindex import SeiznRetriever
from llama_index.llms.openai import OpenAI
from llama_index.core.query_engine import RetrieverQueryEngine

# Initialize the Seizn retriever
retriever = SeiznRetriever(
    api_key=os.environ["SEIZN_API_KEY"],
    dataset="my-docs",
    top_k=5,
    threshold=0.7,
)

# Create a query engine with the retriever
llm = OpenAI(model="gpt-4")
query_engine = RetrieverQueryEngine.from_args(
    retriever=retriever,
    llm=llm,
)

# Query your documents
response = query_engine.query(
    "How do I configure rate limiting?"
)

print(response.response)
# Access the trace for debugging
print("Trace:", response.metadata.get("seizn_trace"))

04เคล็ดลับสำหรับ Production

Streaming Response

เปิดใช้งาน Streaming เพื่อประสบการณ์ผู้ใช้ที่ดีขึ้นสำหรับการตอบกลับที่ยาว

typescript
const queryEngine = new RetrieverQueryEngine(retriever, llm);

// Enable streaming response
const stream = await queryEngine.query(
  'Explain the authentication flow',
  { streaming: true }
);

for await (const chunk of stream) {
  process.stdout.write(chunk.response);
}

Hybrid Search

รวมการค้นหาเวกเตอร์และคำสำคัญเพื่อ Recall ที่ดีขึ้น

typescript
const retriever = new SeiznRetriever({
  apiKey: process.env.SEIZN_API_KEY,
  dataset: 'my-docs',
  searchMode: 'hybrid', // vector + keyword
  hybridAlpha: 0.7,     // 70% vector, 30% keyword
});

Node Postprocessor

เชื่อมต่อ Postprocessor สำหรับการกรองและจัดอันดับใหม่ขั้นสูง

typescript
import { SimilarityPostprocessor, KeywordNodePostprocessor } from 'llamaindex';

const queryEngine = new RetrieverQueryEngine(retriever, llm, {
  nodePostprocessors: [
    new SimilarityPostprocessor({ similarityCutoff: 0.7 }),
    new KeywordNodePostprocessor({
      requiredKeywords: ['authentication'],
      excludeKeywords: ['deprecated'],
    }),
  ],
});

05การแก้ไขปัญหา

ข้อผิดพลาดสาเหตุวิธีแก้ไข
SEIZN_AUTH_ERRORAPI Key ไม่ถูกต้องหรือไม่มีตรวจสอบตัวแปรสภาพแวดล้อม SEIZN_API_KEY
SEIZN_DATASET_NOT_FOUNDไม่พบชื่อชุดข้อมูลตรวจสอบว่าชุดข้อมูลมีอยู่ในแดชบอร์ด
Low relevance scoresคำค้นหาไม่ตรงกับเอกสารลอง Hybrid Search หรือปรับ Threshold