Skip to content

Context Retrieval: Revel text-to-Cypher and context generation method #118

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

galshubeli
Copy link
Contributor

@galshubeli galshubeli commented Jul 7, 2025

Summary by CodeRabbit

  • New Features

    • Added support for streaming QA responses, allowing users to receive answers incrementally as they are generated.
  • Improvements

    • Enhanced error handling for Cypher query generation, providing clearer feedback when issues occur.
    • Clarified usage examples in documentation for both full QA pipeline and standalone query generation.
    • Centralized initialization of QA and query generation steps for better performance and consistency.
    • Extracted ontology cleaning to a standalone function for improved modularity.
    • Refactored streaming functionality to use a unified QA step, removing redundant components.
  • Bug Fixes

    • Unified and streamlined the question-answering process for improved reliability and consistency.

@galshubeli galshubeli requested a review from swilly22 July 7, 2025 14:59
Copy link

coderabbitai bot commented Jul 7, 2025

Walkthrough

The changes refactor streaming QA functionality by removing the StreamingQAStep class and integrating its logic into the existing QAStep and ChatSession classes. The ChatSession class now centralizes step initialization, adds new configuration parameters, improves error handling, and clarifies usage examples. Ontology cleaning is extracted to a standalone function.

Changes

File(s) Change Summary
graphrag_sdk/chat_session.py Refactored to remove StreamingQAStep; integrated streaming into QAStep via run_stream; centralized step initialization; added system instruction and prompt template parameters; improved error handling in cypher generation; extracted ontology cleaning to standalone function; updated usage examples.
graphrag_sdk/steps/qa_step.py Added run_stream method to QAStep for streaming QA responses, yielding incremental chunks.
graphrag_sdk/steps/stream_qa_step.py Deleted file; removed entire StreamingQAStep class and related streaming logic.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ChatSession
    participant QAStep
    participant GraphQueryGenerationStep

    User->>ChatSession: send_message(message)
    ChatSession->>GraphQueryGenerationStep: generate_cypher_query(message)
    GraphQueryGenerationStep-->>ChatSession: cypher, context
    ChatSession->>QAStep: run(question, cypher, context)
    QAStep-->>ChatSession: answer
    ChatSession-->>User: answer
Loading
sequenceDiagram
    participant User
    participant ChatSession
    participant QAStep
    participant GraphQueryGenerationStep

    User->>ChatSession: send_message_stream(message)
    ChatSession->>GraphQueryGenerationStep: generate_cypher_query(message)
    GraphQueryGenerationStep-->>ChatSession: cypher, context
    ChatSession->>QAStep: run_stream(question, cypher, context)
    QAStep-->>ChatSession: answer chunks (stream)
    ChatSession-->>User: answer chunks (stream)
Loading

Possibly related PRs

Suggested labels

enhancement, Impact S, Review effort 2/5

Suggested reviewers

  • swilly22
  • gkorland

Poem

A bunny hopped through streaming code,
Refactored steps, a lighter load.
No more streaming steps apart—
QA flows with a single heart.
Ontology cleaned, the prompt is bright,
Now answers stream both day and night!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 14d3e27 and 5feec7a.

📒 Files selected for processing (1)
  • graphrag_sdk/chat_session.py (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • graphrag_sdk/chat_session.py
⏰ 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: test (openai/gpt-4.1)
  • GitHub Check: Analyze (python)
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 191fab9 and 2858ee5.

📒 Files selected for processing (3)
  • graphrag_sdk/chat_session.py (6 hunks)
  • graphrag_sdk/steps/qa_step.py (2 hunks)
  • graphrag_sdk/steps/stream_qa_step.py (0 hunks)
💤 Files with no reviewable changes (1)
  • graphrag_sdk/steps/stream_qa_step.py
🧰 Additional context used
🧬 Code Graph Analysis (1)
graphrag_sdk/steps/qa_step.py (3)
graphrag_sdk/chat_session.py (1)
  • send_message_stream (181-212)
graphrag_sdk/models/litellm.py (1)
  • send_message_stream (239-275)
graphrag_sdk/models/model.py (1)
  • send_message_stream (106-107)
🪛 Ruff (0.11.9)
graphrag_sdk/chat_session.py

133-133: Local variable e is assigned to but never used

Remove assignment to unused variable e

(F841)

🔇 Additional comments (8)
graphrag_sdk/steps/qa_step.py (2)

2-2: LGTM!

The Iterator import is appropriately added to support the new streaming functionality.


54-74: Well-implemented streaming functionality!

The new run_stream method cleanly extends the QAStep class with streaming capabilities while maintaining consistency with the existing run method. The implementation correctly yields chunks from the underlying chat session's streaming method.

graphrag_sdk/chat_session.py (6)

26-38: Excellent documentation improvements!

The expanded examples clearly demonstrate both the full QA pipeline and standalone Cypher query generation use cases. This will help users understand the different ways to interact with the chat session.


41-96: Good architectural improvements!

The constructor changes enhance the design by:

  • Making configuration explicit through well-documented parameters
  • Initializing steps once for better performance
  • Properly separating concerns by extracting ontology cleaning

The persistent step instances will improve efficiency by avoiding repeated instantiation.


108-112: Clean helper method!

Good refactoring to centralize the response update logic, ensuring both the session and cypher step stay synchronized.


157-179: Clean refactoring of send_message!

The method now properly leverages the refactored components:

  • Uses the public generate_cypher_query method
  • Utilizes the persistent qa_step instance
  • Correctly handles error cases
  • Updates the response using the centralized helper

191-212: Excellent streaming implementation!

The refactored streaming method properly:

  • Leverages the new qa_step.run_stream method
  • Ensures the complete response is captured from chat history
  • Maintains consistency with the non-streaming method
  • Updates the last response after streaming completes

214-239: Good extraction of ontology cleaning logic!

The standalone function properly encapsulates the ontology cleaning logic, making it reusable and testable. The implementation correctly removes the 'unique' and 'required' attributes as intended.

Copy link

@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)
graphrag_sdk/chat_session.py (1)

131-138: Remove unused exception variable.

The exception variable e is captured but never used, as flagged by the static analysis tool.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2858ee5 and 14d3e27.

📒 Files selected for processing (1)
  • graphrag_sdk/chat_session.py (6 hunks)
🧰 Additional context used
🪛 Ruff (0.11.9)
graphrag_sdk/chat_session.py

133-133: Local variable e is assigned to but never used

Remove assignment to unused variable e

(F841)

🔇 Additional comments (5)
graphrag_sdk/chat_session.py (5)

26-38: Great documentation improvements!

The expanded examples clearly demonstrate both the full QA pipeline and standalone Cypher query generation, making the API more accessible to users.


84-96: Excellent refactoring for performance optimization.

Initializing the QA and cypher steps once during construction instead of per-call instantiation is a significant performance improvement. This centralizes step management and eliminates unnecessary object creation overhead.


143-179: Well-structured message handling implementation.

The method correctly:

  • Uses the persistent QA step instance for better performance
  • Handles error cases with appropriate fallbacks
  • Maintains consistent response structure
  • Updates the last complete response for state management

181-212: Solid streaming implementation.

The streaming method properly:

  • Handles cypher generation errors with early return
  • Uses the new run_stream method from the persistent QA step
  • Correctly extracts the final answer from chat history
  • Maintains state consistency with the last complete response

108-111: Good addition for state management.

This helper method follows DRY principles by centralizing the logic for updating both the session's last complete response and the cypher step's last answer, ensuring consistent state management.

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