🦙Chính thức

Tích hợp LlamaIndex

Native retriever cho query engine LlamaIndex với streaming và hybrid search.

01Tổng quan 60 giây

SeiznRetriever triển khai giao diện BaseRetriever của LlamaIndex, giúp tương thích với tất cả query engine và pipeline LlamaIndex.

  • Tích hợp native với query engine LlamaIndex
  • Hỗ trợ streaming response ngay lập tức
  • Tương thích với node postprocessor LlamaIndex

02Cài đặt

Cài đặt Seizn SDK cùng với LlamaIndex.

Installationbash
# TypeScript / JavaScript
npm install seizn llamaindex

# Python
pip install seizn llama-index

03Ví dụ 5 phút

Xây dựng query engine với SeiznRetriever cho ứng dụng RAG của bạn.

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"))

04Mẹo cho Production

Streaming Response

Bật streaming để trải nghiệm người dùng tốt hơn với phản hồi dài.

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

Kết hợp tìm kiếm vector và từ khóa để recall tốt hơn.

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

Xâu chuỗi postprocessor cho lọc và reranking nâng cao.

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

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

05Xử lý sự cố

LỗiNguyên nhânGiải pháp
SEIZN_AUTH_ERRORAPI key không hợp lệ hoặc thiếuKiểm tra biến môi trường SEIZN_API_KEY
SEIZN_DATASET_NOT_FOUNDKhông tìm thấy tên datasetXác minh dataset tồn tại trong bảng điều khiển
Low relevance scoresTruy vấn không khớp tài liệuThử hybrid search hoặc điều chỉnh threshold