Skip to content

spec: using typed version of ComputeAttributes for compute_attributes - #247

Merged
mattcuento merged 4 commits into
nextfrom
mc/compute-attributes-rich-typing
Jul 28, 2026
Merged

spec: using typed version of ComputeAttributes for compute_attributes#247
mattcuento merged 4 commits into
nextfrom
mc/compute-attributes-rich-typing

Conversation

@mattcuento

@mattcuento mattcuento commented Jul 28, 2026

Copy link
Copy Markdown

Wiring in the codegen ComputeAttributes type as stainless won't handle the custom type (from apigen) on its own.

Hand-type the compute_attributes query param as
Dict[str, ComputeAttributes] using the apigen union in custom.py,
across namespace_query_params, namespace_explain_query_params, and
namespace_multi_query_params.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@mattcuento mattcuento changed the title Rich compute_attributes typing (Path B override) spec: using typed version of ComputeAttributes for compute_attributes Jul 28, 2026
…float])

The committed custom.py carried a stale ComputeAttributesVectorDist using
Vector; current apigen emits Sequence[float] (per the inline VectorDist spec
change). Regenerated via scripts/gen so 'supplemental generated code' is current.
compute_attributes is now Dict[str, ComputeAttributes], so the generated
{"foo": "bar"} mocks no longer typecheck. Use the Highlight tuple
("Highlight", "bar"), mirroring how aggregate_by uses ("Sum", "bar").
@mattcuento
mattcuento marked this pull request as ready for review July 28, 2026 15:59
Exercises every variant of the ComputeAttributes union (VectorDist,
Highlight, HighlightWithConfig, RankBy) through the request-body
serialization path (maybe_transform over NamespaceQueryParams) and
asserts the JSON wire form for each.

Placed in a non-skipped module so it runs in CI (the generated
api_resources tests and test_transform.py are skipped).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@cursor cursor Bot 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.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 6c9d176. Configure here.

# to normalize tuples -> lists, then assert structural equality.
assert json.loads(json.dumps(serialized)) == expected_wire, (
f"variant {variant!r} serialized to {serialized!r}, expected {expected_wire!r}"
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Test JSON dumps tuples

Medium Severity

The new compute_attributes serialization test fails with a TypeError because it uses stdlib json.dumps to round-trip values. maybe_transform returns tuples, which stdlib json.dumps cannot serialize, preventing the test from verifying the wire format that orjson correctly produces for client requests.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 6c9d176. Configure here.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

uh, no it doesn't, tests are passing

@mattcuento
mattcuento merged commit 002cb4c into next Jul 28, 2026
8 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