Skip to content

feat: structure RAG context output to respect relationship directionality #807#808

Open
suhaniiz wants to merge 2 commits into
param20h:devfrom
suhaniiz:feature/layout-direction-807
Open

feat: structure RAG context output to respect relationship directionality #807#808
suhaniiz wants to merge 2 commits into
param20h:devfrom
suhaniiz:feature/layout-direction-807

Conversation

@suhaniiz

@suhaniiz suhaniiz commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

📋 PR Checklist

Thank you for contributing to PDF-Assistant-RAG! 🎉
Please fill out this template before submitting. PRs without it filled in will be closed.


🔗 Related Issue

Closes #807


📝 What does this PR do?

This PR resolves the issue where the knowledge graph relationship context returned to the LLM had its subject/object orientation scrambled due to alphabetical key deduplication.

  • Modified get_entity_context to capture the matched query entity explicitly as the primary subject.
  • Preserved alphabetical handling solely behind the scenes within dedup_key to maintain safe weight accumulation and co-occurrence deduplication.
  • Updated the Markdown output rendering string loop to dynamically match the new orientation-aware structural keys (item['subject'] and item['object']).

This ensures that the final RAG context sentences present information naturally from the user's search intent perspective (e.g., "Apple is related to Fruit" instead of randomly outputting "Fruit is related to Apple").


🗂️ Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • 🔧 Refactor / code cleanup
  • 📝 Documentation update
  • 🎨 UI / styling change
  • ⚙️ CI / tooling / config change
  • 🧪 Tests

🧪 How was this tested?

  • Ran the backend locally (uvicorn app.main:app --reload)
  • Tested the affected API endpoints manually via sending user queries and inspecting the generated Markdown context string blocks.

📸 Screenshots (if UI change)

N/A


⚠️ Anything to flag for reviewers?

The core underlying graph structure remains safely undirected (nx.Graph). This fix handles orientation layout gracefully strictly at the dictionary tracking and response formulation levels, ensuring zero breaking changes to existing data pipeline parsers.


✅ Self-Review Checklist

  • My branch is based on dev, not main
  • I have not added any secrets / API keys
  • I have not modified main branch or any HuggingFace deployment config
  • My code follows the existing style (no unnecessary formatting changes)
  • I have updated relevant docs / comments if needed

@suhaniiz suhaniiz requested a review from param20h as a code owner July 7, 2026 04:58
@vercel

vercel Bot commented Jul 7, 2026

Copy link
Copy Markdown

@suhaniiz is attempting to deploy a commit to the param20h's projects Team on Vercel.

A member of the Team first needs to authorize it.

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.

[Enhancement]: Make LLM context output layout aware of relationship directionality

1 participant