在几天而非几周内构建生产级 RAG 系统:介绍 ShinRAG

发布: (2025年12月2日 GMT+8 21:06)
4 min read
原文: Dev.to

Source: Dev.to

构建一个可投入生产的检索增强生成(RAG)系统通常需要 6–12 周,这并不是因为 RAG 逻辑本身复杂,而是因为周边基础设施:向量数据库、嵌入流水线、编排代码、分块策略以及 API 集成等。

ShinRAG 是一个可视化 RAG 平台,让你专注于业务逻辑,能够在 几天 而不是几周内交付生产级 RAG 系统。

构建生产 RAG 系统的挑战

  • 基础设施复杂度 – 搭建向量存储、嵌入服务和编排层。
  • 时间投入 – 从想法到生产需要 6–12 周。
  • 维护开销 – 持续的调试和优化。
  • 供应商锁定 – 难以切换工具或提供商。

介绍 ShinRAG

ShinRAG 是一站式托管 RAG 平台,提供:

  • 可视化流水线构建器(拖拽式 RAG 工作流)
  • 托管向量数据库(由 Qdrant 提供支持)
  • 带数据集分配的 RAG 代理
  • 完整的 REST API,适用于生产环境
  • TypeScript SDK,便于集成
  • 使用追踪与监控

安装

npm install @shinrag/sdk
# or
pnpm add @shinrag/sdk

基本用法

查询代理

import { ShinRAGClient } from '@shinrag/sdk';

const client = new ShinRAGClient({
  apiKey: 'sk_your_api_key_here',
});

const result = await client.queryAgent('agent_1234567890abcdef', {
  question: 'What are the key features mentioned in the documentation?',
  maxResults: 5,
  temperature: 0.7,
});

console.log('Answer:', result.answer);
console.log('Sources:', result.sources);
console.log('Tokens used:', result.tokensUsed);

代理会自动:

  • 搜索分配的数据集
  • 检索相关上下文
  • 生成带引用的答案
  • 追踪 token 使用情况

查询流水线

const pipelineResult = await client.queryPipeline('pipeline-id', {
  input: 'Process this query through my custom pipeline',
});

if (pipelineResult.status === 'completed') {
  console.log('Output:', pipelineResult.output);
  console.log('Total tokens:', pipelineResult.totalTokensUsed);

  // 检查各节点结果
  pipelineResult.nodeResults.forEach(node => {
    console.log(`Node ${node.nodeId}: ${node.status}`);
    if (node.output) {
      console.log(`  Output: ${node.output}`);
    }
  });
}

语义搜索

const searchResult = await client.queryDataset({
  datasetId: 'dataset_1234567890abcdef',
  queryText: 'What are the key features?',
  limit: 10,
});

if (searchResult.success) {
  console.log(`Found ${searchResult.results.length} results`);
  searchResult.results.forEach(item => {
    console.log(`Score: ${item.score}, Content: ${item.payload.text}`);
  });
}

高级特性

元数据过滤

const result = await client.queryAgent('agent-id', {
  question: 'Find information about TypeScript',
  filter: {
    must: [
      { key: 'category', match: { value: 'programming' } },
      { key: 'difficulty', range: { gte: 1, lte: 3 } },
    ],
  },
});

TypeScript 类型

interface QueryAgentResponse {
  answer: string | null;
  sources: Array;
  tokensUsed: number;
  model: string;
  warning?: string;
}

错误处理

import { ShinRAGClient, ShinRAGError } from '@shinrag/sdk';

try {
  const result = await client.queryAgent('agent-id', {
    question: 'Your question here',
  });
} catch (error) {
  if (error instanceof ShinRAGError) {
    console.error('API Error:', error.message);
    console.error('Status Code:', error.statusCode);
  }
}

使用场景

  • 内部知识库 – 上传公司文档,创建代理,通过 API 或聊天集成进行查询。
  • 客服机器人 – 导入常见问题解答,使用过滤器,部署到客服系统。
  • 技术文档问答 – 为每个主题创建独立代理,使用过滤模板路由查询。

架构与技术栈

ComponentTechnology
APINestJS
Vector storageQdrant
LLM providersOpenAI, Anthropic, custom APIs
SDKTypeScript (with full type safety)
API styleRESTful
Monitoring & analyticsBuilt‑in usage tracking

路线图

  • 更多流水线节点类型
  • 流式响应
  • Python、Go 等语言的 SDK
  • 增强的监控与分析仪表盘
  • 集成市场

入门指南

  1. shinrag.com 注册(或自行部署实例)。
  2. 创建第一个数据集并上传文档。
  3. 构建代理并分配数据集。
  4. 安装 SDK(npm install @shinrag/sdk)。
  5. 开始查询!

Tags

#rag #ai #typescript #machinelearning #developer #api #nlp #vectordatabase

Back to Blog

相关文章

阅读更多 »

切换账户

@blink_c5eb0afe3975https://dev.to/blink_c5eb0afe3975 正如大家所知,我正重新开始记录我的进展,我认为最好在一个不同的…

Strands 代理 + Agent Core AWS

入门指南:Amazon Bedrock AgentCore 目录 - 前置要求(requisitos‑previos) - 工具包安装(instalación‑del‑toolkit) - 创建…