Skip to content

Conversation

@nikazzio
Copy link
Member

@nikazzio nikazzio commented May 26, 2025

This PR enhances chat functionality by introducing optional collection support, a new chain, and a simple conversation mode to chat with a model using history, but without a reference document collections.
Also history handling has been updated to allow missing collections without errors.

  • Add conversation_rag_chain alongside a streamlined conversation_chain for test mode
  • Update /chat endpoint to select between RAG and conversation chains via a new mode field
  • Change add_history to accept non-existent collections and adjust related tests

Changes

Show a summary per file
File Description
brevia/routers/qa_router.py Introduced mode to ChatBody, routing logic for RAG/conversation modes
brevia/query.py Refactored conversation_chain and introduced conversation_rag_chain
brevia/models.py Changed LOREM_IPSUM to a JSON-formatted string literal
brevia/chat_history.py Modified add_history to handle missing collections without raising
tests/test_query.py Added tests for simple and RAG conversation chains and output format
tests/test_chat_history.py Updated test to expect successful history addition with no collection
tests/routers/test_qa_router.py Added tests for invalid mode and missing collection in /chat route

Copy link
Contributor

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.

Pull Request Overview

Enhance chat functionality by making document collections optional and introducing separate chains for RAG-based and simple chats.

  • Make collection optional in the /chat endpoint and adjust routing logic to pick between RAG and simple chains.
  • Rename the existing conversation_chain to conversation_rag_chain and add a new conversation_chain for non-collection chats.
  • Update chat history persistence to allow collection_id to be None if no collection is provided.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
brevia/routers/qa_router.py Made collection optional, added chain-selection logic, updated docstring
brevia/query.py Renamed RAG chain, added a standalone simple conversation_chain
brevia/chat_history.py Allow collection_id to be None and removed error on missing collection
Comments suppressed due to low confidence (4)

brevia/routers/qa_router.py:61

  • The variable conversation_handler is instantiated but never used; consider passing it to the chain callbacks or removing it to avoid dead code.
conversation_handler = ConversationCallbackHandler()

brevia/query.py:286

  • Consider adding unit tests to cover the new conversation_chain function to verify its output formatting and behavior without a collection.
def conversation_chain(

brevia/chat_history.py:119

  • Removing the error when a provided collection isn't found may lead to silent failures; consider reintroducing error handling or at least logging a warning when CollectionStore.get_by_name returns None.
if collection:

brevia/query.py:5

  • Double-check that all symbols used in the new conversation_chain (e.g., get_settings, StrOutputParser, RunnablePassthrough, load_condense_prompt) are imported; missing imports will cause runtime errors.
from langchain_core.output_parsers import JsonOutputParser

@stefanorosanelli stefanorosanelli requested a review from Copilot May 29, 2025 13:01
Copy link
Contributor

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.

Pull Request Overview

Enhances chat functionality by introducing optional collection support, a new RAG-based chain, and a simple test mode; also updates history handling to allow missing collections without errors.

  • Add conversation_rag_chain alongside a streamlined conversation_chain for test mode
  • Update /chat endpoint to select between RAG and test chains via a new mode field
  • Change add_history to accept non-existent collections and adjust related tests

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/test_query.py Added tests for simple and RAG conversation chains and output format
tests/test_chat_history.py Updated test to expect successful history addition with no collection
tests/routers/test_qa_router.py Added tests for invalid mode and missing collection in /chat route
brevia/routers/qa_router.py Introduced mode to ChatBody, routing logic for RAG/test modes
brevia/query.py Refactored conversation_chain and introduced conversation_rag_chain
brevia/models.py Changed LOREM_IPSUM to a JSON-formatted string literal
brevia/chat_history.py Modified add_history to handle missing collections without raising
Comments suppressed due to low confidence (3)

tests/test_chat_history.py:34

  • [nitpick] The test name test_add_history_failure no longer matches its behavior (it no longer checks for a failure). Consider renaming it to something like test_add_history_no_collection for clarity.
def test_add_history_failure():

brevia/routers/qa_router.py:39

  • Using a mutable default value for chat_history can lead to shared state across requests. Consider using Field(default_factory=list) to provide a new list per instance.
    chat_history: list = []

brevia/models.py:27

  • The multiline string for LOREM_IPSUM includes an unescaped newline inside the JSON string, which is invalid JSON and may cause parsing errors. Either escape the newline or adjust the format so the JSON remains valid.
    "answer": "Lorem ipsum dolor sit amet, consectetur adipisici elit,

@stefanorosanelli stefanorosanelli changed the title feat: enhance chat functionality with optional collection support and… Enhance chat functionality, support no-RAG use case May 29, 2025
@stefanorosanelli stefanorosanelli changed the title Enhance chat functionality, support no-RAG use case Enhance chat functionality, support conversation (no-RAG) use case May 30, 2025
brevia/query.py Outdated
"""

# Define your desired data structure.
class Result(BaseModel):
Copy link
Contributor

@stefanorosanelli stefanorosanelli May 30, 2025

Choose a reason for hiding this comment

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

can we remove this Result class? seems unused now

@stefanorosanelli stefanorosanelli merged commit 28ca5f0 into main May 30, 2025
20 checks passed
@stefanorosanelli stefanorosanelli deleted the feat-230/chat-no-rag-api branch May 30, 2025 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants