npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

autocoder-rag-sdk

v0.0.7

Published

Node.js SDK for AutoCoder RAG - 便于在Node.js代码中调用auto-coder.rag run功能

Readme

AutoCoder RAG SDK for Node.js

一个便于在Node.js/TypeScript代码中调用auto-coder.rag run功能的SDK,用于文档问答和检索增强生成。

特性

  • 🚀 易于使用: 提供简洁直观的API接口
  • 🔄 异步优先: 基于Promise和AsyncGenerator的现代异步设计
  • 📡 流式处理: 支持实时流式输出答案
  • 🛠 完整配置: 支持所有auto-coder.rag run命令行选项
  • 📦 TypeScript优先: 完整的类型定义和类型安全

安装

cd rag-sdks/nodejs
pnpm install
pnpm run build

快速开始

基础用法

import { AutoCoderRAGClient } from 'autocoder-rag-sdk';

const client = new AutoCoderRAGClient('/path/to/docs');

const answer = await client.query('如何使用这个项目?');
console.log(answer);

流式输出

import { AutoCoderRAGClient } from 'autocoder-rag-sdk';

const client = new AutoCoderRAGClient('/path/to/docs');

for await (const chunk of client.queryStream('这个项目的主要功能是什么?')) {
  process.stdout.write(chunk);
}

获取上下文

import { AutoCoderRAGClient } from 'autocoder-rag-sdk';

const client = new AutoCoderRAGClient('/path/to/docs');

const response = await client.queryWithContexts('如何安装?');

console.log(`答案: ${response.answer}`);
console.log(`上下文数量: ${response.contexts?.length || 0}`);

高级配置

import { AutoCoderRAGClient, RAGConfig } from 'autocoder-rag-sdk';

const config: RAGConfig = {
  docDir: '/path/to/docs',
  model: 'v3_chat',
  modelFile: '/path/to/model_config.yaml',  // 模型配置文件(可选)
  agentic: true,  // 使用 AgenticRAG
  productMode: 'pro',
  enableHybridIndex: true,
};

const client = new AutoCoderRAGClient(config);

const answer = await client.query('项目架构是什么?');
console.log(answer);

使用模型配置文件

如果你需要使用自定义的模型配置文件,可以通过 modelFile 参数指定:

import { AutoCoderRAGClient } from 'autocoder-rag-sdk';

const client = new AutoCoderRAGClient({
  docDir: '/path/to/docs',
  modelFile: '/path/to/model_config.yaml',  // 模型配置文件
});

// 也可以在查询时覆盖
const answer = await client.query('如何使用这个项目?', {
  modelFile: '/path/to/another_model_config.yaml',
});
console.log(answer);

自定义命令路径

如果你的 auto-coder.rag 命令安装在非标准位置,可以通过 commandPath 配置项指定命令路径:

import { AutoCoderRAGClient } from 'autocoder-rag-sdk';

const client = new AutoCoderRAGClient({
  docDir: '/path/to/docs',
  commandPath: '/usr/local/bin/auto-coder.rag',  // 自定义命令路径
});

const answer = await client.query('如何使用这个项目?');
console.log(answer);

API 文档

AutoCoderRAGClient

class AutoCoderRAGClient {
  constructor(config: RAGConfig | string);
  query(question: string, options?: RAGQueryOptions): Promise<string>;
  queryStream(question: string, options?: RAGQueryOptions): AsyncGenerator<string>;
  queryWithContexts(question: string, options?: RAGQueryOptions): Promise<RAGResponse>;
  getVersion(): string;
  checkAvailability(): boolean;
}

示例

运行示例:

pnpm run example:basic
pnpm run example:stream

许可证

MIT License