Skip to content

Bug: Duplicate Responses in 'generate' mode #190

Open
@schmichri

Description

@schmichri

In generate mode NLWeb returns the same answer twice.

Bug Report: Duplicate Responses from Ask Endpoint

Issue Description

When asking a question through the /ask endpoint, the system returns the same response twice. The response data with format {"message_type": "nlws", "answer": "something"} is being sent twice for a single request.

Image

Steps to Reproduce

  1. Setup NLWeb + Import Data
  2. set the generate mode in index.html chat_interface = new ChatInterface('', 'nlwebsearch', 'generate');
  3. Send a request to the /ask endpoint
  4. Observe the response stream

Expected Behavior

The system should send a single response for each request, containing the answer and any relevant item descriptions.

Actual Behavior

The system sends two identical responses:

  1. An initial response with just the answer
  2. A second response with the same answer and item descriptions

Root Cause

In the synthesizeAnswer method of the GenerateAnswer class, the code was sending an initial message with just the answer before processing URLs:

# Create initial message with just the answer
message = {"message_type": "nlws", "answer": answer, "items": json_results}
logger.info("Sending initial answer")
await self.send_message(message)

Then, after processing URLs and item descriptions, it would send another message with the same answer plus the item descriptions.

Solution

The fix involved removing the initial message sending, ensuring that the response is sent exactly once in all cases:

  1. If there are no ranked answers, it sends a message with a default answer and empty items list
  2. If there are URLs and description tasks, it sends a message with the answer and item descriptions
  3. If there are no URLs found in the synthesis response, it sends a message with just the answer and empty items list
  4. If there's an error, it sends an error message

This ensures that each request receives exactly one response, eliminating the duplicate message issue.

Image

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions