Skip to content

feat(convert): support explicit type hints in engine value encoding #807

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

Merged
merged 15 commits into from
Aug 19, 2025

Conversation

lemorage
Copy link
Contributor

@lemorage lemorage commented Jul 26, 2025

Context

#792 (comment)

Cause

The problem was that encode_engine_value couldn't distinguish between:

  1. Empty dicts that should be KTables (should become [])
  2. Empty dicts that should be JSON objects (should stay {})

Solution

Make encode_engine_value function context-aware by adding an optional _in_struct and type_hint params.

The logic now:
- When encoding struct fields, if the type-hint denotes it is a JSON, it stays what it is, otherwise becomes [] (assuming KTable)
- When encoding standalone values (_in_struct=False): empty dicts stay {}

Pass type hints when calling encode_engine_value function, so it will be explicitly known how we handle each value.

Copy link
Member

@badmonster0 badmonster0 left a comment

Choose a reason for hiding this comment

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

Thanks a lot for taking care of this, @lemorage!

Copy link
Member

@badmonster0 badmonster0 left a comment

Choose a reason for hiding this comment

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

Thanks a lot for starting this deep refactoring, which solves the problem more systematically!

@lemorage lemorage changed the title feat(convert): improve dict handling with type hints in value encoding feat(convert): support explicit type hints in engine value encoding Jul 30, 2025
@badmonster0 badmonster0 merged commit fb92792 into cocoindex-io:main Aug 19, 2025
6 checks passed
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