Skip to content

docs(rag): document SearchResultItem support in build_context / deduplicate_chunks#435

Open
MervinPraison wants to merge 1 commit into
mainfrom
claude/issue-431-20260530-0606
Open

docs(rag): document SearchResultItem support in build_context / deduplicate_chunks#435
MervinPraison wants to merge 1 commit into
mainfrom
claude/issue-431-20260530-0606

Conversation

@MervinPraison
Copy link
Copy Markdown
Owner

Summary

Changes

  • docs/rag/module.mdx: Updated Context Utilities section with Tabs examples, added result item formats table, updated ContextBuilderProtocol signature
  • docs/rag/retrieval.mdx: Added cross-reference note about SearchResultItem objects
  • docs/knowledge/overview.mdx: Added Note about SearchResultItem return format

Test Plan

  • All code examples use correct imports from praisonaiagents.rag and praisonaiagents.knowledge.models
  • Examples are copy-paste runnable
  • Mintlify components used appropriately (Tabs, Note)
  • Follows AGENTS.md style guidelines

Fixes #431

🤖 Generated with Claude Code

…licate_chunks (fixes #431)

- Updated docs/rag/module.mdx with new signatures accepting Union[Dict, SearchResultItem]
- Added Tabs examples showing both dict and SearchResultItem usage
- Documented metadata fallback behavior for source/filename lookup
- Added cross-references in docs/rag/retrieval.mdx and docs/knowledge/overview.mdx
- Follows AGENTS.md style guidelines with Mintlify components

Co-authored-by: Mervin Praison <MervinPraison@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 30, 2026 06:08
@qodo-code-review
Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 30, 2026

Warning

Review limit reached

@MervinPraison, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 57 minutes and 40 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ca79d833-5ea9-4439-8c82-ce8f831dcc46

📥 Commits

Reviewing files that changed from the base of the PR and between a74a6b7 and 9541e67.

📒 Files selected for processing (3)
  • docs/knowledge/overview.mdx
  • docs/rag/module.mdx
  • docs/rag/retrieval.mdx
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/issue-431-20260530-0606

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.

Copy link
Copy Markdown

@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 pull request updates the documentation across several files to indicate that RAG context utilities, such as build_context and deduplicate_chunks, now directly support SearchResultItem objects and mixed inputs with automatic metadata fallback. However, the review feedback highlights a critical discrepancy: the underlying implementation in praisonaiagents/rag/context.py does not currently support these objects directly, which would result in runtime AttributeErrors. To resolve this, either the RAG context utility implementation must be updated to support SearchResultItem objects and the documented fallback behavior, or the documentation must be corrected to instruct users to convert these objects to dictionaries first.

Comment on lines +62 to +64
<Note>
Knowledge search returns `SearchResultItem` objects (see `praisonaiagents.knowledge.models`) that can be passed directly into RAG context utilities like `build_context` and `deduplicate_chunks`.
</Note>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

This note states that SearchResultItem objects can be passed directly into build_context and deduplicate_chunks. However, doing so currently raises an AttributeError because those utility functions expect dictionaries and call .get() on the items.

Please update this note to mention that they must be converted to dictionaries first (e.g., using [r.to_dict() for r in results]), or ensure that the underlying RAG context utilities are updated to support SearchResultItem objects directly.

Comment thread docs/rag/module.mdx
Comment on lines +216 to +239
<Tab title="SearchResultItem results">
```python
from praisonaiagents.rag import build_context, deduplicate_chunks
from praisonaiagents.knowledge.models import SearchResultItem

# SearchResultItem format
results = [
SearchResultItem(text="First content", source="a.pdf", filename="a.pdf"),
SearchResultItem(text="Second content", source="b.pdf", filename="b.pdf"),
]

# Mixed dict + object input also works
results.append({"text": "Third content", "metadata": {"filename": "c.pdf"}})

# Build context from SearchResultItem objects
context, used_results = build_context(
results=results,
max_tokens=2000,
include_source=True,
)

unique = deduplicate_chunks(results)
```
</Tab>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The code example shown here will raise an AttributeError: 'SearchResultItem' object has no attribute 'get' at runtime.

In praisonaiagents/rag/context.py, both build_context and deduplicate_chunks expect dictionaries and call .get("text"), .get("memory"), and .get("metadata") directly on the items in the results list. They do not currently support SearchResultItem objects directly.

To make this example work with the current codebase, the SearchResultItem objects must be converted to dictionaries first using .to_dict():

# Convert SearchResultItem objects to dicts before passing to context utilities
dict_results = [r.to_dict() if hasattr(r, "to_dict") else r for r in results]

context, used_results = build_context(
    results=dict_results,
    max_tokens=2000,
    include_source=True,
)

Alternatively, the implementation of build_context and deduplicate_chunks in praisonaiagents/rag/context.py should be updated to handle both dict and object types (similar to how DefaultCitationFormatter handles them using isinstance or getattr).

Comment thread docs/rag/module.mdx
Comment on lines +242 to +254
<Note>
`build_context` and `deduplicate_chunks` accept a mix of `dict` results and `SearchResultItem` objects. When `include_source=True`, the label is taken from `metadata["filename"]` / `metadata["source"]` first, falling back to the top-level `filename` / `source` attribute on the item, and finally to `Source N`.
</Note>

### Result Item Formats

The context utilities support two input formats with automatic fallback for metadata lookups:

| Lookup | 1st choice | 2nd choice | Fallback |
|--------|------------|------------|----------|
| `source` | `metadata["source"]` | `item.source` (object) / `item["source"]` (dict) | `""` |
| `filename` | `metadata["filename"]` | `item.filename` / `item["filename"]` | `""` |
| `text` | `item.text` / `item["text"]` | `item.memory` / `item["memory"]` | `""` (item skipped in `build_context`) |
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The fallback behavior described in this note and table does not match the actual implementation in praisonaiagents/rag/context.py.

Currently, build_context only looks up metadata.get("source") and metadata.get("filename"). It does not fall back to top-level attributes like item.source or item.filename, nor does it support attribute/key lookups on SearchResultItem objects (which will cause an AttributeError as noted above).

Please either:

  1. Update the implementation of build_context and deduplicate_chunks in praisonaiagents/rag/context.py to match this documented fallback behavior.
  2. Or update this documentation to accurately reflect that only dictionary inputs with metadata keys are supported.

Comment thread docs/rag/retrieval.mdx
Comment on lines +160 to +161
# Note: Each retrieved item is a SearchResultItem object (see praisonaiagents.knowledge.models)
# that can be passed directly into build_context / deduplicate_chunks
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

This note indicates that SearchResultItem objects can be passed directly into build_context / deduplicate_chunks. As noted in other files, this is currently not supported by the implementation in praisonaiagents/rag/context.py and will result in an AttributeError.

Please update this comment to reflect the need for dictionary conversion (e.g., r.to_dict()) or update the context utilities to support objects.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

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.

docs(rag): document SearchResultItem support in build_context / deduplicate_chunks (PR #1739)

2 participants