[BUG]: chunk_rag_data crashes with ValueError when perspective is a dict, silently dropping RAG vector storage

未关闭 适合新手
#175 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

@agarwalpranav0711 已经在做这个了。

开始于 2026年10月15日。

  • #176 来自 @agarwalpranav0711 —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
82/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
backend

调研方向

从 backend/app/modules/vector_store/chunk_rag_data.py 开始,该文件中 chunk_rag_data() 在第 61 行附近使用 hasattr() 校验 data['perspective']。运行 issue 中的复现片段以确认 ValueError,并查看 langgraph_nodes/store_and_send.py,了解 dict 如何传入此函数。完成标准是:同时包含两个键的 dict 输入能够被分块,缺少键时抛出描述清晰的错误,对象输入仍然可用,并且单元测试覆盖每种情况。

由索引模型根据 Issue 内容生成。

描述

bug

Fix Perspective Validation for Dictionary Inputs in chunk_rag_data

Bug Description

In backend/app/modules/vector_store/chunk_rag_data.py, the chunk_rag_data() function validates the perspective data using hasattr() on data["perspective"].

However, when perspective is provided as a standard Python dictionary, as can happen when deserializing LangGraph pipeline state or JSON payloads, hasattr() returns False for dictionary keys. This causes the function to raise a ValueError even when all required fields are present.

The current validation logic is:

perspective_obj = data["perspective"]

if not (
    hasattr(perspective_obj, "perspective")
    and hasattr(perspective_obj, "reasoning")
):
    raise ValueError("Perspective object missing required fields")

For dictionary inputs, the required fields must be checked using dictionary key access or an equivalent mapping-aware validation approach.

Steps to Reproduce
  1. Open a terminal in the backend/ directory with the project virtual environment activated.
  2. Run the following Python snippet:
from app.modules.vector_store.chunk_rag_data import chunk_rag_data

sample_state = {
    "cleaned_text": "Sample text for chunking and article ID generation.",
    "perspective": {
        "perspective": "Synthesized counter perspective narrative.",
        "reasoning": "Underlying tradeoffs and evidentiary counter-arguments."
    },
    "facts": [
        {
            "original_claim": "Claim 1",
            "verdict": "Verified",
            "explanation": "Evidence description",
            "source_link": "https://example.com"
        }
    ]
}

chunk_rag_data(sample_state)
Actual Behavior

The function raises a ValueError even though the perspective dictionary contains both required fields:

ValueError: Perspective object missing required fields

The error is logged by chunk_rag_data() and prevents the supplied data from being processed successfully.

Expected Behavior
  • The function should accept perspective data represented as a standard dictionary when the required fields are present.
  • Validation should correctly check for the perspective and reasoning keys in dictionary inputs.
  • Missing or invalid required fields should produce a descriptive validation error.
  • Existing behavior for supported perspective object types should be preserved.
  • Valid input should proceed through the normal chunking process.
Logs and Screenshots
[ERROR] [app.modules.vector_store.chunk_rag_data]: Failed to chunk the data: Perspective object missing required fields

Traceback (most recent call last):
  File "backend/app/modules/vector_store/chunk_rag_data.py", line 61, in chunk_rag_data
    raise ValueError("Perspective object missing required fields")
ValueError: Perspective object missing required fields
Environment Details
  • OS: Windows / Linux / macOS
  • Python: 3.13
  • File: backend/app/modules/vector_store/chunk_rag_data.py
  • Related module: backend/app/modules/langgraph_nodes/store_and_send.py
Impact

Severity: Medium — Valid dictionary-based pipeline state is rejected during chunking, potentially disrupting downstream vector storage and retrieval workflows.

Proposed Solution
  1. Replace the hasattr()-only validation with mapping-aware validation for dictionary inputs.
  2. Check that both perspective and reasoning are present and contain valid values before processing.
  3. Preserve compatibility with existing supported object-based inputs, if required.
  4. Add unit tests covering valid dictionaries, missing fields, invalid values, and supported object inputs.
Code of Conduct
主要语言
TypeScript
星标
58
派生
90
平均合并
11 小时 51 分钟
30 天内合并 PR
3

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

AOSSIE-Org/Perspective 的其他 Issue

查看 AOSSIE-Org/Perspective 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。