Skip to content

feat(ai): introduce retrieval domain models and validation - #869

Open
aotenjou wants to merge 5 commits into
apache:masterfrom
aotenjou:OSPP-pr1
Open

feat(ai): introduce retrieval domain models and validation#869
aotenjou wants to merge 5 commits into
apache:masterfrom
aotenjou:OSPP-pr1

Conversation

@aotenjou

@aotenjou aotenjou commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Summary

Introduce the foundational retrieval domain model layer for the AI module.

This PR defines the typed data structures required by the retrieval pipeline, including source documents, text chunks, graph references, evidence, and version metadata. It also adds JSON serialization/deserialization and centralized model validation.

#860 #863 #864

Changes

  • Add retrieval document models:
    • SourceDocument
    • SourceRef
    • TextChunk
  • Add retrieval graph models:
    • EntityRef
    • GraphVertexRef
    • GraphEdgeRef
    • GraphPathRef
  • Add retrieval evidence models:
    • Evidence
    • EvidenceKind
    • ChannelScore
  • Add retrieval version models:
    • GraphVersion
    • IndexVersion
  • Add JSON codec support through RetrievalModelJson
  • Add centralized validation and RetrievalModelValidationException
  • Use field-based equality semantics without introducing stable IDs
  • Add unit tests and JSON fixtures covering model construction, equality, validation, and serialization behavior

How was this PR tested?

  • Tests have Added for the changes
  • Production environment verified

@aotenjou

aotenjou commented Sep 6, 2026

Copy link
Copy Markdown
Contributor Author

@yaozhongq @kitalkuyo-gita

@yaozhongq yaozhongq self-assigned this Sep 7, 2026
@yaozhongq
yaozhongq self-requested a review September 7, 2026 02:27
@yaozhongq yaozhongq assigned aotenjou and unassigned yaozhongq Sep 7, 2026
@yaozhongq
yaozhongq requested a lite review from Copilot September 9, 2026 02:38

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The new unit test includes a tautological hashCode assertion (always passes), and a small UTF-8 handling fix is needed to match existing repository practices.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Introduces a foundational retrieval domain model layer for geaflow-ai, defining immutable value objects and a validated JSON boundary intended to keep model construction/validation deterministic and consistent across ingestion/retrieval.

Changes:

  • Adds retrieval domain model types (documents, graph refs, evidence, and version identifiers) with sameIdentityAs identity semantics distinct from equals.
  • Adds centralized constructor validation helpers/exceptions (ModelValidation, RetrievalModelValidationException).
  • Adds a validated JSON codec (RetrievalModelJson) plus unit tests and JSON fixtures for round-tripping and validation behavior.
File summaries
File Description
geaflow-ai/src/main/java/org/apache/geaflow/ai/retrieval/codec/RetrievalModelJson.java Validated JSON serialization/deserialization that routes through public constructors to enforce invariants.
geaflow-ai/src/main/java/org/apache/geaflow/ai/retrieval/model/package-info.java Package-level contract documentation for identity semantics and JSON compatibility/validation expectations.
geaflow-ai/src/main/java/org/apache/geaflow/ai/retrieval/model/document/SourceDocument.java Source document metadata value object with identity comparison and validation.
geaflow-ai/src/main/java/org/apache/geaflow/ai/retrieval/model/document/TextChunk.java Position-aware chunk model with offset/range validation and identity semantics.
geaflow-ai/src/main/java/org/apache/geaflow/ai/retrieval/model/document/SourceRef.java Citation/span reference model with paired-offset validation.
geaflow-ai/src/main/java/org/apache/geaflow/ai/retrieval/model/graph/EntityRef.java Entity reference model with sorted/immutable collections for stable equality.
geaflow-ai/src/main/java/org/apache/geaflow/ai/retrieval/model/graph/GraphVertexRef.java Vertex reference model with full-field identity/equality.
geaflow-ai/src/main/java/org/apache/geaflow/ai/retrieval/model/graph/GraphEdgeRef.java Edge reference model with sorted provenance chunk IDs and identity semantics.
geaflow-ai/src/main/java/org/apache/geaflow/ai/retrieval/model/graph/GraphPathRef.java Ordered path model enforcing hop/vertex/edge count invariants.
geaflow-ai/src/main/java/org/apache/geaflow/ai/retrieval/model/evidence/Evidence.java Evidence container with identity based on nested reference identities and multiset semantics.
geaflow-ai/src/main/java/org/apache/geaflow/ai/retrieval/model/evidence/EvidenceKind.java Evidence kind enum for retrieval payload categorization.
geaflow-ai/src/main/java/org/apache/geaflow/ai/retrieval/model/evidence/ChannelScore.java Per-channel scoring/ranking metadata with range validation.
geaflow-ai/src/main/java/org/apache/geaflow/ai/retrieval/model/version/GraphVersion.java Graph snapshot identifier value object.
geaflow-ai/src/main/java/org/apache/geaflow/ai/retrieval/model/version/IndexVersion.java Index snapshot identifier tied to a source graph version.
geaflow-ai/src/main/java/org/apache/geaflow/ai/retrieval/validation/ModelValidation.java Centralized validation + defensive-copy helpers used by the models.
geaflow-ai/src/main/java/org/apache/geaflow/ai/retrieval/validation/RetrievalModelValidationException.java Dedicated exception type for model-boundary validation failures.
geaflow-ai/src/test/java/org/apache/geaflow/ai/retrieval/model/RetrievalDomainModelTest.java Unit tests covering identity/equality, validation, and JSON round-trips.
geaflow-ai/src/test/resources/retrieval/model/source-document.json JSON fixture for SourceDocument round-trip.
geaflow-ai/src/test/resources/retrieval/model/evidence.json JSON fixture for a fully-populated Evidence round-trip.
geaflow-ai/src/test/resources/retrieval/model/identity-cases.json Fixture documenting field-based identity comparisons across models.
Review details
  • Files reviewed: 20/20 changed files
  • Comments generated: 2
  • Review effort level: Lite

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

private String readFixture(String name) throws IOException {
InputStream stream = getClass().getClassLoader().getResourceAsStream(name);
Assertions.assertNotNull(stream);
try (BufferedReader reader = new BufferedReader(new InputStreamReader(stream, "UTF-8"))) {
return rank;
}

public boolean sameIdentityAs(Evidence other) {

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.

sameIdentityAs ignores both evidenceId and text, comparing only kind and the four reference collections. However, the codec explicitly supports legacy evidence without references and normalizes missing collections to empty ones. As a result, unrelated entries such as CHUNK/"Alice" and CHUNK/"Bob" are considered identical and may be incorrectly merged, causing evidence to be lost. Please either require at least one identity-bearing reference or fall back to comparing text and/or evidenceId when all reference collections are empty.

@yaozhongq

Copy link
Copy Markdown
Contributor

Also, please link this PR to the parent issue so that everyone can understand the motivation and context behind these changes.

aotenjou and others added 2 commits September 9, 2026 12:09
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@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.

3 participants