Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于实现文件分析功能/ About the RAG function #2

Open
snakeying opened this issue Sep 19, 2024 · 0 comments
Open

关于实现文件分析功能/ About the RAG function #2

snakeying opened this issue Sep 19, 2024 · 0 comments
Assignees
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@snakeying
Copy link
Owner

有朋友问我是否可以实现文件分析功能(RAG),这里统一回复一下:

1. 理论上流程可行 ✅

整个流程的设计是可行的,主要步骤如下:

  • 用户通过 Telegram Bot 上传文件。
  • 使用 file-type 进行 MIME 类型检测。
  • 对文件进行分块处理。
  • 调用外部存储机制(如 Cloudflare 的 R2)存储分块。
  • 使用 OpenAI 等 API 对分块内容进行 embedding。
  • 最终调用 Chat Completion 接口输出结果。

从文件解析、内容分块到嵌入和检索,再到与 GPT 的交互,整个过程在技术上是可以逐步实现的。然而,分块过程中的不可控性是主要瓶颈

2. 为什么会有瓶颈?🤔

  • 内容不可控:用户上传的文件内容差异极大,即使限定了文件类型(如 PDF、TXT、DOCX),内部结构仍可能千变万化。例如,一个 PDF 文件可能包含文本、图表、图片,另一个则可能是纯文字,导致无法采用统一的分块策略。

  • 分块策略难以完美适配:目前分块主要依据文件的外在形式(如页数、段落、字符数),无法精确理解内容的语义结构。这种策略在面对复杂文档(如含大量引用或交叉内容)时,可能会出现失效的情况。

3. 嵌入阶段的连锁反应 🔗

  • 分块质量影响嵌入效果:由于分块阶段的不可控性,后续的嵌入和检索过程无法保证最佳效果。如果分块不符合内容逻辑,嵌入结果可能缺乏上下文支持,直接影响 GPT 对问题的理解和回答的准确性。

4. 最终输出的准确性难以保证 ⚠️

  • 即使嵌入技术在后续环节中表现良好,分块策略导致的上下文缺失和信息不连贯问题依然无法完全弥补。用户最终得到的回答可能因此受到影响,出现不够准确或不完整的情况。

5. 多个 API 协同,增加了系统复杂性 🚨

  • 整个流程至少需要调用 3 个 API 协同工作,任何一个环节出错(如网络波动等)都会导致整体流程无法顺利进行。

希望这能解答大家的疑问!如果有其他问题,欢迎继续讨论 😊。


Some friends have asked whether it's possible to implement the document analysis feature (RAG). Here's a unified response:

1. Theoretically, the process is feasible ✅

The overall workflow is technically feasible, and the main steps are as follows:

  • Users upload files through the Telegram Bot.
  • Use file-type to detect the MIME type.
  • Split the file into chunks.
  • Call an external storage solution (e.g., Cloudflare R2) to store the chunks.
  • Use APIs like OpenAI to embed the chunks.
  • Finally, call the Chat Completion API to output results.

From file parsing, content chunking, embedding, retrieval, to interaction with GPT, the process can be gradually implemented with current technology. However, the uncontrollability of chunking is the main bottleneck.

2. Why is there a bottleneck? 🤔

  • Uncontrollable content: The content of user-uploaded files varies widely. Even if the file types are restricted (e.g., PDF, TXT, DOCX), the internal structure can differ significantly. For instance, one PDF file might contain text, charts, and images, while another could be purely textual. This makes it difficult to apply a unified chunking strategy.

  • Chunking strategy is hard to adapt perfectly: Current chunking methods rely mainly on external characteristics such as the number of pages, paragraphs, or characters, which makes it impossible to precisely grasp the semantic structure of the content. In complex documents (e.g., those with many references or cross-references), this approach might fail.

3. Chain reaction in the embedding phase 🔗

  • Chunk quality affects embedding results: Due to the imprecision in the chunking phase, the subsequent embedding and retrieval processes can't guarantee optimal results. If chunks don't align with the logical flow of the content, embedding results may lack sufficient context, which will directly affect GPT's understanding and the accuracy of its responses.

4. Final output accuracy is hard to guarantee ⚠️

  • Even if embedding techniques perform well later in the process, the contextual gaps and discontinuities caused by the chunking strategy cannot be fully compensated. As a result, the final answers users receive may be affected and could be inaccurate or incomplete.

5. Multiple APIs working together increases system complexity 🚨

  • The entire process requires at least three APIs to work together. If any one step fails (e.g., due to network issues), the whole workflow may break down.

I hope this clarifies the questions! If there are any further inquiries, feel free to discuss 😊.

@snakeying snakeying added help wanted Extra attention is needed good first issue Good for newcomers labels Sep 19, 2024
@snakeying snakeying self-assigned this Sep 19, 2024
@snakeying snakeying pinned this issue Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant