Skip to content

[Search] Add knowledge base retrieve stream convenience APIs - #50210

Open
Xiaofei Cao (XiaofeiCao) wants to merge 9 commits into
Azure:copilot/generate-azure-search-sdk-2026-08-01-previewfrom
XiaofeiCao:search-retrieve-stream
Open

[Search] Add knowledge base retrieve stream convenience APIs#50210
Xiaofei Cao (XiaofeiCao) wants to merge 9 commits into
Azure:copilot/generate-azure-search-sdk-2026-08-01-previewfrom
XiaofeiCao:search-retrieve-stream

Conversation

@XiaofeiCao

@XiaofeiCao Xiaofei Cao (XiaofeiCao) commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Description

Adds regeneration-safe convenience APIs for knowledge-base retrieveStream on top of #49988.

Testing

Add regeneration-safe retrieveStream convenience APIs, typed knowledge-base stream events, and Search-local SSE parsing and lifecycle support.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: eecc64df-f690-4410-b68c-b45e323ec918
Remove the generated zero-argument helper that calls an overload no longer present after the synonym-map listing API update.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: eecc64df-f690-4410-b68c-b45e323ec918
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
34 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

private static final String RESPONSE_COMPLETED_JSON = "{\"statusCode\":200,\"response\":{}}";

@Test
public void convertsAllStreamEventVariants() {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

event model/wrapper deserialization tests

*/
@Generated
@ServiceMethod(returns = ReturnType.COLLECTION)
public Flux<ServerSentEvent<KnowledgeBaseRetrievalStreamEvent>>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

async retrieveStream

*/
@Generated
@ServiceMethod(returns = ReturnType.SINGLE)
public void retrieveStream(KnowledgeBaseRetrievalOptions retrievalRequest,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

sync retrieveStream

Keep knowledge base stream event dispatch and payload decoding in the unexported knowledgebases implementation package while preserving generated client wiring.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: eecc64df-f690-4410-b68c-b45e323ec918
Keep the target branch's repaired synonym-map convenience method and preserve the regeneration-safe knowledge base retrieve stream implementation.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: eecc64df-f690-4410-b68c-b45e323ec918
/**
* Represents a knowledge base retrieval stream event that is not recognized by this SDK version.
*/
public final class UnknownKnowledgeBaseRetrievalStreamEvent extends KnowledgeBaseRetrievalStreamEvent {

@XiaofeiCao Xiaofei Cao (XiaofeiCao) Aug 24, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

For unknown events, we'll not throw exception, but put them all in this UnknownKnowledgeBaseRetrievalStreamEvent.

Welcome suggestions.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this is fine. I believe the other langs are doing the same

Treat terminal predicates as inclusive early-stop signals while allowing EOF and HTTP 204 responses to complete normally without terminal events.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: eecc64df-f690-4410-b68c-b45e323ec918
Keep Search-specific knowledge base stream coverage while relying on the Azure Core SSE PR for generic parser, Flux, response, and lifecycle tests.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: eecc64df-f690-4410-b68c-b45e323ec918
@XiaofeiCao
Xiaofei Cao (XiaofeiCao) marked this pull request as ready for review August 24, 2026 07:35
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
34 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR adds regeneration-safe, typed server-sent events (SSE) convenience APIs for Knowledge Base retrieveStream in azure-search-documents, including Search-local SSE parsing utilities and typed wrappers for known knowledge-base events with a forward-compatible “unknown event” fallback.

Changes:

  • Introduces Search-local SSE public models (ServerSentEvent, ServerSentEventListener) and internal stream parsing/lifecycle utilities.
  • Adds typed Knowledge Base retrieval stream event wrappers + converter, and new sync/async retrieveStream convenience APIs that emit/dispatch typed SSE events.
  • Adds focused tests for stream event conversion and client integration, and updates the changelog.

Reviewed changes

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

Show a summary per file
File Description
sdk/search/azure-search-documents/src/test/java/com/azure/search/documents/knowledgebases/KnowledgeBaseRetrievalStreamTests.java Adds tests validating typed event conversion and sync/async streaming behavior.
sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/ServerSentEventListener.java Adds public sync listener contract for SSE consumption.
sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/ServerSentEvent.java Adds public typed SSE event model and internal construction hook.
sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/implementation/sse/ServerSentEventStreams.java Adds facade utilities to decode/listen to SSE streams from a single response.
sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/implementation/sse/ServerSentEventStreamResponse.java Validates SSE response status/content-type and supports body cancellation.
sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/implementation/sse/ServerSentEventStream.java Implements SSE decoding and sync listener processing.
sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/models/implementation/sse/ServerSentEventHelper.java Internal accessor helper for constructing ServerSentEvent.
sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/knowledgebases/models/KnowledgeBaseRetrievalStreamEvent.java Adds base type for typed KB retrieval stream events + terminal flag.
sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/knowledgebases/models/UnknownKnowledgeBaseRetrievalStreamEvent.java Adds raw-data fallback model for unknown event names.
sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/knowledgebases/models/KnowledgeBaseRetrievalStartedStreamEvent.java Adds typed wrapper for retrieval.started.
sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/knowledgebases/models/KnowledgeBaseActivityStartedStreamEvent.java Adds typed wrapper for activity.started.
sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/knowledgebases/models/KnowledgeBaseActivityCompletedStreamEvent.java Adds typed wrapper for activity.completed.
sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/knowledgebases/models/KnowledgeBaseAnswerCompletedStreamEvent.java Adds typed wrapper for answer.completed.
sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/knowledgebases/models/KnowledgeBaseReferencesCompletedStreamEvent.java Adds typed wrapper for references.completed.
sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/knowledgebases/models/KnowledgeBaseErrorStreamEvent.java Adds typed terminal wrapper for error.
sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/knowledgebases/models/KnowledgeBaseResponseCompletedStreamEvent.java Adds typed terminal wrapper for response.completed.
sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/knowledgebases/implementation/KnowledgeBaseRetrievalStreamEventConverter.java Adds event-name-to-typed-model conversion logic.
sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/knowledgebases/KnowledgeBaseRetrievalClient.java Adds new public sync retrieveStream(..., listener) convenience API.
sdk/search/azure-search-documents/src/main/java/com/azure/search/documents/knowledgebases/KnowledgeBaseRetrievalAsyncClient.java Adds new public async retrieveStream(...) convenience API returning Flux.
sdk/search/azure-search-documents/customizations/src/main/java/SearchCustomizations.java Injects regeneration-safe additions for SSE + KB streaming APIs/models.
sdk/search/azure-search-documents/CHANGELOG.md Documents the newly added typed SSE streaming APIs and models.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: eecc64df-f690-4410-b68c-b45e323ec918
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: eecc64df-f690-4410-b68c-b45e323ec918

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

High-level design thought, instead of inlining all the custom code here without IDE capabilities, why not add a utility class in implementation which adds these features and then the customizations here are just having the Knowledge Base clients calling those methods

Co-authored-by: Alan Zimmer <48699787+alzimmermsft@users.noreply.github.com>
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.

4 participants