Skip to content

Conversation

@dingyi222666
Copy link
Member

This PR adds LightRAG as a new RAG (Retrieval-Augmented Generation) retriever implementation, expanding the available RAG strategies beyond the existing standard and HippoRAG retrievers.

New Features

  • LightRAG Retriever: Add complete LightRAG retriever implementation with ~645 lines of core logic
    • Implements knowledge graph-based retrieval approach
    • Supports multiple search modes: naive, local, global, and hybrid
    • Provides entity and relationship extraction capabilities
    • Includes configurable chunking and embedding strategies
  • Type System Integration: Extend RAG type system to include 'light_rag' as a supported retriever type
  • Service Factory Support: Integrate LightRAG into the RAG service factory with reactive computed ref support
  • Documentation Updates: Update vector database configuration links to point to official chatluna.chat documentation

Other Changes

  • Remove unused @e2b/code-interpreter dependency from extension-tools package
  • Add WebFetch localhost permission to Claude settings for development
  • Improve documentation clarity for Faiss database installation warnings

Technical Details

The LightRAG implementation follows the same pattern as existing retrievers:

  • Exported via packages/service-vector-store/src/rag/lightrag/index.ts (443 lines)
  • Type definitions in packages/service-vector-store/src/rag/lightrag/type.ts (202 lines)
  • Properly integrated into the retriever factory pattern in src/service/rag.ts
  • Maintains compatibility with existing embeddings and LLM configuration system

Add new LightRAG retriever as an alternative RAG strategy alongside standard and HippoRAG retrievers. This implementation provides another option for retrieval-augmented generation with different performance characteristics.

- Add LightRAG retriever implementation in packages/service-vector-store/src/rag/lightrag/
- Update RAG retriever type system to support 'light_rag' type
- Integrate LightRAG into RAG service factory with computed ref support
- Update documentation links to point to chatluna.chat domain
- Remove unused @e2b/code-interpreter dependency from extension-tools
- Add WebFetch localhost permission to Claude settings
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @dingyi222666, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This PR primarily adds the LightRAG retriever, a new graph-based RAG strategy, to the system. It includes the full implementation of LightRAG, its integration into the existing RAG type system and service factory, and updates to documentation links for vector databases. Minor changes include removing an unused dependency and updating Claude permissions.

Highlights

  • Intent: This pull request introduces LightRAG as a new Retrieval-Augmented Generation (RAG) retriever implementation, significantly expanding the available RAG strategies beyond the existing standard and HippoRAG retrievers. The goal is to provide a graph-based retrieval approach with advanced capabilities.
  • Key Changes: A complete implementation of the LightRAG retriever has been added, featuring graph-based retrieval, support for multiple search modes (naive, local, global, hybrid), and capabilities for entity and relationship extraction. This new retriever is fully integrated into the RAG type system, adding 'light_rag' as a supported retriever type, and is supported by the RAG service factory with reactive computed ref support. Additionally, documentation links for vector database configurations (Faiss, Redis, Milvus) have been updated to point to official chatluna.chat documentation, and the warning message regarding Faiss installation has been improved for clarity.
  • Other Notable Changes: The unused @e2b/code-interpreter dependency has been removed from the extension-tools package. For development purposes, WebFetch(domain:localhost) permission has been added to the Claude settings. The documentation for Faiss database installation warnings has been improved for clarity.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 8, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

此次变更在向量存储包中新增 LightRAG 检索器实现与完整类型定义,扩展 RAG 类型与导出并在 ChatLunaRAGService 中接入创建逻辑;同时调整顶层使用示例文本与安全声明,并在核心/扩展中添加若干中间件与插件接入。

Changes

Cohort / File(s) Summary
Usage 文本与示例
packages/service-vector-store/src/index.ts
修改插件初始化示例以传入配置(ctx.plugin(ChatLunaRAGService, config));替换/新增指引链接(ChatLuna 指南、Redis、Milvus),移除旧 LangChain 链接并精简安全声明文本。
RAG 总入口与类型扩展
packages/service-vector-store/src/rag/index.ts
light_rag 加入 RAGRetrieverType 联合;扩展 RAGRetrieverConfigRAGRetrieverInstance 的类型分支以支持 light_rag;新增并导出 LightRAGRetrievercreateLightRAGRetrieverLightRAGRetrieverConfig
LightRAG 运行时实现
packages/service-vector-store/src/rag/lightrag/index.ts
新增 LightRAGRetriever 类:含 baseUrl 校验与 /health 健康检查、懒初始化、统一请求头、HTTP 接口封装(addDocuments/similaritySearch/listDocuments/deleteDocuments/getStats 等)、图谱实体/关系操作(getGraphLabels/getKnowledgeGraph/...)、错误处理与 dispose;提供工厂 createLightRAGRetriever
LightRAG 类型定义
packages/service-vector-store/src/rag/lightrag/type.ts
新增基于 OpenAPI 的完整 TypeScript 类型声明(文档、插入/查询请求响应、图谱实体/关系、分页与状态结构等),仅类型定义,无运行时代码。
服务层接入与构造调整
packages/service-vector-store/src/service/rag.ts
createRAGRetriever 中新增 light_rag 分支,构建 LightRAG 配置(embeddings 与可选 llm)并调用 createLightRAGRetriever;将 Service 构造调用改为 super(ctx, 'chatluna_rag', true)
基类泛型化
packages/service-vector-store/src/rag/base.ts
BaseRAGRetriever 改为泛型 BaseRAGRetriever<T extends RetrieverConfig = RetrieverConfig>,构造器接收 config: T,以支持子类强类型配置。
现有检索器类型适配
packages/service-vector-store/src/rag/hipporag/index.ts, packages/service-vector-store/src/rag/standard/index.ts
HippoRAGRetrieverStandardRAGRetriever 改为继承 BaseRAGRetriever 的相应泛型(HippoRAGRetrieverConfig / StandardRAGRetrieverConfig),并移除对 config 的显式类型断言以使用强类型配置。
核心中间件调整
packages/core/src/middleware.ts
引入并在主中间件流水线中加入新增的 preset 相关中间件(add_preset、clone_preset、delete_preset、list_all_preset、set_preset),调整中间件顺序/去重。
扩展插件接入
packages/extension-long-memory/src/plugin.ts
新增本地插件 prompt_varaiable 的导入并将其插入 middlewares(位于 init_layer 后、search_memory 前)。

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Caller as 调用方
  participant Service as ChatLunaRAGService
  participant RAGIndex as rag/index
  participant LR as LightRAGRetriever
  participant Server as LightRAG Server (HTTP)

  rect rgb(245,248,255)
    note over Caller,Service: 创建 light_rag 检索器
    Caller->>Service: createRAGRetriever(type="light_rag", cfg)
    Service->>RAGIndex: 请求 createLightRAGRetriever
    RAGIndex->>LR: new LightRAGRetriever(cfg)
    LR-->>Service: ComputedRef<Retriever>
    Service-->>Caller: 返回检索器引用
  end

  rect rgb(245,255,245)
    note over Caller,LR: 相似度检索流程(懒初始化 + HTTP 查询)
    Caller->>LR: similaritySearch(query, k)
    LR->>LR: lazy init -> GET /health (若未初始化)
    LR->>Server: POST /query/data (query payload)
    Server-->>LR: QueryDataResponse (200)
    LR-->>Caller: 映射为 Documents(含图谱片段/元数据)
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Poem

我在代码田里蹦跳来,🥕
新的检索织起轻羽栈,
文档成串入图海,
查询如风穿林来,
小兔为改动摆尾欢。

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed 标题准确反映了此次新增 LightRAG API 检索器实现的主要改动,简洁且聚焦于核心功能扩展,能让团队成员迅速了解本次 PR 的目的。
Description Check ✅ Passed PR 描述详细说明了新增 LightRAG 检索器的核心功能、类型系统集成、服务工厂支持及文档更新等改动,且与实际代码变更保持一致。
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/light-rag

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@dingyi222666 dingyi222666 changed the title [Feature] Add LightRAG retriever implementation [Feature] Add LightRAG (API) retriever implementation Oct 8, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This is a great feature addition, introducing the LightRAG retriever. The implementation is well-structured and follows the existing patterns in the codebase. I have a few suggestions to improve performance, consistency, and clarity in the new LightRAGRetriever implementation.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (6)
packages/service-vector-store/src/index.ts (2)

72-74: 文档链接更新看起来合理,但请确认可用性与 i18n 一致性

  • 请确认 3 个链接均已发布且可访问,避免用户点击 404。
  • 使用提示全部为中文,是否需要在 en-US usage 中同步英文指引?

76-76: 安全声明表述建议更明确

当前“可能导致 koishi 环境不安全/不负直接责任”的措辞较笼统。建议说明具体风险点与缓解措施(如编译依赖、系统库、Node 升级影响范围),并将免责声明放入文档而非 usage 弹窗,减少用户困惑。

packages/service-vector-store/src/rag/lightrag/type.ts (1)

12-21: 补充单条文本插入请求类型以对齐实现

实现侧使用的是单条插入端点 /documents/text 且字段为 file_source,而此处仅有批量 InsertTextsRequestfile_sources)。为降低歧义,建议新增:

export interface InsertTextRequest {
  text: string
  file_source?: string
}

并在注释中标注两个端点的差异与适用场景。

packages/service-vector-store/src/service/rag.ts (1)

61-73: 接入逻辑正确,行为与其他检索器一致

新增的 light_rag 分支与既有 hippo_rag/standard 路径一致,计算依赖与类型映射正确。

可选:两处分支(hippo_rag/light_rag)构造配置的样板代码可提取为小工具函数以减少重复。

packages/service-vector-store/src/rag/lightrag/index.ts (2)

177-182: 实体/关系仅附加到首条文档,可能导致调用方遗漏上下文

若调用方逐条消费文档,建议将 entities/relationships(以及可选的 query_metadata)附加到每条返回文档,或者在返回结构中单独返回一份全局元数据,避免信息丢失。

-        // Attach entities and relationships to the metadata of the first document
-        if (returnedDocs.length > 0) {
-            returnedDocs[0].metadata.entities = result.data.entities
-            returnedDocs[0].metadata.relationships = result.data.relationships
-            returnedDocs[0].metadata.query_metadata = result.metadata
-        }
+        if (returnedDocs.length > 0) {
+            for (const d of returnedDocs) {
+                d.metadata.entities = result.data.entities
+                d.metadata.relationships = result.data.relationships
+                d.metadata.query_metadata = result.metadata
+            }
+        }

87-121: 批量插入顺序串行,吞吐较低;可选:增加并发上限以提升性能

当前逐条 POST 保存了元数据,但在大批量导入时会较慢。建议增加可配置并发(如 4~8)并使用 Promise.allSettled 控制失败不阻塞整体。

是否需要我提交一个带有限流(不引入新依赖)的实现草案?

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0575c9d and 97cceb5.

⛔ Files ignored due to path filters (2)
  • .claude/settings.local.json is excluded by !**/*.json
  • packages/extension-tools/package.json is excluded by !**/*.json
📒 Files selected for processing (5)
  • packages/service-vector-store/src/index.ts (1 hunks)
  • packages/service-vector-store/src/rag/index.ts (2 hunks)
  • packages/service-vector-store/src/rag/lightrag/index.ts (1 hunks)
  • packages/service-vector-store/src/rag/lightrag/type.ts (1 hunks)
  • packages/service-vector-store/src/service/rag.ts (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
packages/service-vector-store/src/service/rag.ts (2)
packages/service-vector-store/src/rag/index.ts (3)
  • RAGRetrieverConfig (20-27)
  • createLightRAGRetriever (15-15)
  • RAGRetrieverInstance (29-37)
packages/service-vector-store/src/rag/lightrag/index.ts (1)
  • createLightRAGRetriever (438-443)
packages/service-vector-store/src/rag/lightrag/index.ts (2)
packages/core/src/utils/request.ts (1)
  • chatLunaFetch (99-120)
packages/service-vector-store/src/rag/lightrag/type.ts (16)
  • InsertResponse (17-21)
  • QueryRequest (31-47)
  • QueryDataResponse (103-108)
  • DocStatus (5-5)
  • DocumentsRequest (139-145)
  • PaginatedDocsResponse (133-137)
  • DeleteDocRequest (147-150)
  • StatusCountsResponse (152-154)
  • PopularLabel (187-190)
  • KnowledgeGraph (182-185)
  • EntityExistsResponse (200-202)
  • EntityUpdateRequest (157-161)
  • GraphEntity (169-173)
  • DeletionResult (192-198)
  • RelationUpdateRequest (163-167)
  • GraphRelation (175-180)
packages/service-vector-store/src/rag/index.ts (1)
packages/service-vector-store/src/rag/lightrag/index.ts (2)
  • LightRAGRetrieverConfig (426-433)
  • LightRAGRetriever (39-421)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: lint
  • GitHub Check: build
🔇 Additional comments (1)
packages/service-vector-store/src/rag/index.ts (1)

3-3: 类型与导出扩展合理

  • 成功将 light_rag 加入公开类型、实例与导出面。
  • 与 service/rag.ts 泛型分发匹配良好。

Also applies to: 15-17, 18-27, 29-37

…d document insertion

Fix service initialization and document insertion logic for LightRAG retriever to ensure proper configuration propagation and batch document processing.

- Pass config to ChatLunaRAGService to enable proper plugin initialization
- Mark ChatLunaRAGService as immediate service for faster initialization
- Refactor addDocuments to use batch API instead of sequential single insertions
- Simplify baseUrl validation logic in initialize method
- Remove unnecessary metadata handling that wasn't supported by the API
Improve type safety across all RAG retriever implementations by adding generic type parameters to BaseRAGRetriever class and adding configurable query mode support for LightRAG.

- Add generic type parameter to BaseRAGRetriever for strongly typed config access
- Update HippoRAGRetriever, LightRAGRetriever, and StandardRAGRetriever to use typed base class
- Add defaultQueryMode configuration option to LightRAGRetrieverConfig
- Support mode parameter in similaritySearch options for LightRAG
- Remove unnecessary type casting in StandardRAGRetriever initialization
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (1)
packages/service-vector-store/src/rag/lightrag/index.ts (1)

67-69: ...
...

...


Need in Chinese.

Example:

"**修正 catch 变量类型导致的编译错误**"

Explain: TS catch variable is unknown, `error.message` compile error. Provide fix.

In diff we show modifications.

Ok.

But also we might want to produce recommended comment for metadata attached to first doc? Should we? The existing comment referencing previously. Should we add? It's optional but we might mention.

But we must ensure we avoid duplication: There is existing comment (Gemini) complaining about metadata attached to first doc. They recommended to attach to all or doc comment. Should we re-raise? It's still unresolved. Maybe we should to show we noticed. For instructions: If we generate new comment similar to past review comment, we must tag with . But we can also provide new reasoning maybe more precise? But to avoid conflict we can maybe escalate even more? previous comment from gemini flagged as medium. Since not resolved, we can mention? In our review we can mention we agree with previous comment? But to avoid duplication we can note referencing existing comment and tag . But we only produce new comments when necessary. We can maybe mention: "I agree with previous feedback" and supply but instructions? The instructions mention if you generate comment similar to past comment, tag . That may be appropriate to show we support? Do we need to? Not necessary if we don't comment.

Focus on ensuring we have at least the critical comment.

But we also need to abide by instructions: Comments must be in Chinese (zh-CN). Should we mention glimpsed for the fix. Provide diff as per instructions.

Let's craft comment.

Need to record scratchpad.

Also we should ensure we mention comment referencing we not referencing other contexts.

Let's craft.

Need review_comment_start with line ranges.

Possible line range: 67-69 (makes sense). Provide comment.

In diff propose modifications.

Ok.

Also we should finish with file_end.

Let's craft final response.

But before final, update scratchpad for lightrag.

Need to note tasks done.

Add to scratchpad: highlight bug.

Let's update scratchpad accordingly.

Need to add to scratchpad to mention we flagged.

Then produce comment.

Proceed.

Update scratchpad block.

We'll create scratchpad entry, note issue.

Need to ensure scratchpad restful.

Let's produce.

After comment, mark done.

At the end, provide file_end marker.

Ok.

Let's craft comment in final. Need to produce start marker, comment, end marker.

Remember to include diff code block with +/-. (No suggestion identifier). Provide recommended fix.

Also include short explanation.

Let's craft comment:

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 97cceb5 and 6f42764.

📒 Files selected for processing (3)
  • packages/service-vector-store/src/index.ts (2 hunks)
  • packages/service-vector-store/src/rag/lightrag/index.ts (1 hunks)
  • packages/service-vector-store/src/service/rag.ts (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
packages/service-vector-store/src/rag/lightrag/index.ts (3)
packages/service-vector-store/src/rag/index.ts (3)
  • LightRAGRetriever (15-15)
  • LightRAGRetrieverConfig (16-16)
  • createLightRAGRetriever (15-15)
packages/core/src/utils/request.ts (1)
  • chatLunaFetch (99-120)
packages/service-vector-store/src/rag/lightrag/type.ts (16)
  • InsertResponse (17-21)
  • QueryRequest (31-47)
  • QueryDataResponse (103-108)
  • DocStatus (5-5)
  • DocumentsRequest (139-145)
  • PaginatedDocsResponse (133-137)
  • DeleteDocRequest (147-150)
  • StatusCountsResponse (152-154)
  • PopularLabel (187-190)
  • KnowledgeGraph (182-185)
  • EntityExistsResponse (200-202)
  • EntityUpdateRequest (157-161)
  • GraphEntity (169-173)
  • DeletionResult (192-198)
  • RelationUpdateRequest (163-167)
  • GraphRelation (175-180)
packages/service-vector-store/src/service/rag.ts (2)
packages/service-vector-store/src/rag/index.ts (3)
  • RAGRetrieverConfig (20-27)
  • createLightRAGRetriever (15-15)
  • RAGRetrieverInstance (29-37)
packages/service-vector-store/src/rag/lightrag/index.ts (1)
  • createLightRAGRetriever (427-432)
packages/service-vector-store/src/index.ts (1)
packages/service-vector-store/src/service/rag.ts (1)
  • ChatLunaRAGService (15-78)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: build
  • GitHub Check: lint

…n RAG type definitions

Replace 'never' type fallbacks with base RetrieverConfig and BaseRAGRetriever types to improve type system flexibility and allow for future retriever implementations.

- Change RAGRetrieverConfig fallback from 'never' to 'RetrieverConfig'
- Change RAGRetrieverInstance fallback from 'never' to 'BaseRAGRetriever'
- Import BaseRAGRetriever and RetrieverConfig for type definitions
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (5)
packages/service-vector-store/src/rag/lightrag/index.ts (5)

291-328: 重构:避免使用 await + .then() 混合模式

在 lines 303、316、327 等多处使用了 await.then() 的混合模式,这种写法不常见且降低了代码可读性。

建议统一使用 await 模式:

     async getGraphLabels(): Promise<string[]> {
         if (!this._initialized) await this.initialize()
         const response = await chatLunaFetch(
             `${this._baseUrl}/graph/label/list`,
             {
                 headers: this._getHeaders()
             }
         )
         if (!response.ok)
             throw new Error(
                 `Failed to get graph labels: ${response.statusText}`
             )
-        return response.json().then((labels: string[]) => labels)
+        return (await response.json()) as string[]
     }

getPopularLabelssearchLabels 方法应用类似的重构。


330-408: 重构:统一异步模式并保持一致性

在这些图相关方法中(lines 344, 359, 375, 390, 407),同样存在 await + .then() 混合模式。为了代码一致性,建议统一使用 await 模式。

示例重构(适用于所有相关方法):

     async checkEntityExists(name: string): Promise<boolean> {
         if (!this._initialized) await this.initialize()
         const response = await chatLunaFetch(
             `${this._baseUrl}/graph/entity/exists?name=${encodeURIComponent(name)}`,
             { headers: this._getHeaders() }
         )
         if (!response.ok)
             throw new Error(
                 `Failed to check entity existence: ${response.statusText}`
             )
-        const result = await response
-            .json()
-            .then((data) => data as EntityExistsResponse)
+        const result = (await response.json()) as EntityExistsResponse
         return result.exists
     }

418-425: 考虑移除未使用的 llm 属性或添加说明

配置接口中定义了 llm 属性,但在 LightRAGRetriever 类中并未使用。这可能会让开发者在配置检索器时感到困惑。

如果该属性计划用于未来功能,请添加注释说明其用途。否则,应将其移除以避免混淆。


50-74: 修复错误处理中的类型问题

在 TypeScript 中,catch 变量的类型是 unknown,直接访问 error.message 会导致编译错误。

应用此差异修复类型问题:

         } catch (error) {
-            throw new Error(
-                `Failed to connect to LightRAG server: ${error.message}`
-            )
+            const message = error instanceof Error ? error.message : String(error)
+            throw new Error(
+                `Failed to connect to LightRAG server: ${message}`
+            )
         }

115-177: 图数据仅附加到第一个文档,设计不一致

在 lines 169-174,实体和关系数据仅附加到返回的第一个文档的 metadata 中。这使得第一个文档的结构与其他文档不同,可能会让使用此方法的开发者感到困惑和容易出错。

由于更改返回类型 Promise<Document[]> 会破坏 BaseRAGRetriever 的契约,请考虑以下改进方案之一:

  1. 一致性:将元数据附加到所有返回的文档,使它们的结构保持一致。
  2. 清晰的文档说明:如果附加到所有文档过于冗余,请在 similaritySearch 方法上添加详细的 JSDoc 注释,明确警告使用者这种特殊行为以及如何从第一个文档访问额外数据。
🧹 Nitpick comments (2)
packages/service-vector-store/src/rag/standard/index.ts (1)

89-89: 移除不必要的类型断言

由于类已经使用了泛型参数 BaseRAGRetriever<StandardRAGRetrieverConfig>this.config 的类型已经是 StandardRAGRetrieverConfig,不需要再进行类型断言。

应用此差异移除类型断言:

-        const config = this.config as StandardRAGRetrieverConfig
+        const config = this.config
packages/service-vector-store/src/rag/lightrag/index.ts (1)

418-425: 建议添加请求超时配置

所有网络请求(如 initializeaddDocumentssimilaritySearch 等)都缺少超时控制。遇到网络抖动或后端无响应时,请求会无限期挂起,影响用户体验和资源占用。

建议在配置接口中添加超时选项:

 export interface LightRAGRetrieverConfig extends RetrieverConfig {
     /** Base URL of the LightRAG server */
     baseUrl?: string
     /** API Key for the LightRAG server */
     apiKey?: string
     defaultQueryMode?: QueryMode
+    /** Request timeout in milliseconds (default: 15000) */
+    requestTimeoutMs?: number
     llm?: ChatLunaChatModel
 }

然后在发起请求时使用超时控制:

const timeout = this.config.requestTimeoutMs ?? 15000
const response = await chatLunaFetch(`${this._baseUrl}/health`, {
    headers: this._getHeaders(),
    signal: AbortSignal.timeout(timeout)
})

将此模式应用于文件中的所有 chatLunaFetch 调用。

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6f42764 and f4d7bd0.

📒 Files selected for processing (4)
  • packages/service-vector-store/src/rag/base.ts (1 hunks)
  • packages/service-vector-store/src/rag/hipporag/index.ts (1 hunks)
  • packages/service-vector-store/src/rag/lightrag/index.ts (1 hunks)
  • packages/service-vector-store/src/rag/standard/index.ts (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
packages/service-vector-store/src/rag/base.ts (1)
packages/core/src/llm-core/platform/client.ts (1)
  • config (91-93)
packages/service-vector-store/src/rag/standard/index.ts (1)
packages/core/src/llm-core/platform/client.ts (1)
  • config (91-93)
packages/service-vector-store/src/rag/lightrag/index.ts (3)
packages/core/src/utils/request.ts (1)
  • chatLunaFetch (99-120)
packages/service-vector-store/src/rag/base.ts (6)
  • AddDocumentsOptions (113-121)
  • SearchOptions (126-131)
  • ListDocumentsOptions (136-148)
  • DeleteDocumentsOptions (153-158)
  • RetrieverStats (163-175)
  • RetrieverConfig (96-108)
packages/service-vector-store/src/rag/lightrag/type.ts (17)
  • InsertResponse (17-21)
  • QueryMode (23-29)
  • QueryRequest (31-47)
  • QueryDataResponse (103-108)
  • DocStatus (5-5)
  • DocumentsRequest (139-145)
  • PaginatedDocsResponse (133-137)
  • DeleteDocRequest (147-150)
  • StatusCountsResponse (152-154)
  • PopularLabel (187-190)
  • KnowledgeGraph (182-185)
  • EntityExistsResponse (200-202)
  • EntityUpdateRequest (157-161)
  • GraphEntity (169-173)
  • DeletionResult (192-198)
  • RelationUpdateRequest (163-167)
  • GraphRelation (175-180)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: lint
  • GitHub Check: build
🔇 Additional comments (7)
packages/service-vector-store/src/rag/base.ts (1)

13-22: LGTM!泛型设计良好

引入泛型参数 T extends RetrieverConfig 使得子类可以拥有类型安全的配置对象,同时默认类型参数确保了向后兼容性。这为 LightRAG 和其他检索器的强类型配置奠定了基础。

packages/service-vector-store/src/rag/hipporag/index.ts (1)

18-18: LGTM!与泛型模式保持一致

类签名正确更新为使用泛型参数 BaseRAGRetriever<HippoRAGRetrieverConfig>,与 StandardRAGRetriever 和新的 LightRAGRetriever 保持一致。

packages/service-vector-store/src/rag/lightrag/index.ts (5)

44-48: LGTM!构造函数实现正确

构造函数正确初始化了基础 URL 和 API 密钥,提供了合理的默认值 http://localhost:9621


86-113: LGTM!批量添加文档的实现

使用批量端点添加文档是正确的方法,相比逐个添加文档可以显著提高性能。


179-223: LGTM!文档列表功能实现正确

正确实现了分页、过滤和排序功能,并将 API 响应转换为 Document 对象。


225-257: LGTM!文档删除功能实现正确

正确处理了全部删除和按 ID 删除两种场景,错误处理也很完善。


259-288: LGTM!统计信息获取实现正确

正确聚合了不同状态的文档计数,并返回了符合 RetrieverStats 接口的统计信息。

…rsion

Reorganize middleware imports for better readability and register missing prompt_variable plugin in long-memory extension. Bump service-vector-store to alpha.1 for LightRAG release.

- Reorder middleware imports to group preset-related middlewares together
- Register prompt_varaiable plugin in extension-long-memory
- Bump service-vector-store version from 1.3.0-alpha.0 to 1.3.0-alpha.1
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f4d7bd0 and 0f1e79d.

⛔ Files ignored due to path filters (1)
  • packages/service-vector-store/package.json is excluded by !**/*.json
📒 Files selected for processing (3)
  • packages/core/src/middleware.ts (2 hunks)
  • packages/extension-long-memory/src/plugin.ts (2 hunks)
  • packages/service-vector-store/src/rag/index.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/service-vector-store/src/rag/index.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: build
  • GitHub Check: lint
🔇 Additional comments (2)
packages/core/src/middleware.ts (2)

33-37: 预设中间件导入正确。

新增的五个预设相关中间件导入遵循了现有模式,代码结构清晰。


97-101: 中间件注册已验证并通过
所有预设中间件文件存在且正确导出 apply 函数,注册列表中无重复项。

@dingyi222666 dingyi222666 merged commit 68c6b2a into v1-dev Oct 8, 2025
5 checks passed
@dingyi222666 dingyi222666 deleted the feat/light-rag branch October 8, 2025 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants