Skip to content

Consider health scores in the search API#783

Merged
jviotti merged 1 commit intomainfrom
search-health
Mar 25, 2026
Merged

Consider health scores in the search API#783
jviotti merged 1 commit intomainfrom
search-health

Conversation

@jviotti
Copy link
Member

@jviotti jviotti commented Mar 25, 2026

Signed-off-by: Juan Cruz Viotti jv@jviotti.com

Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
@augmentcode
Copy link

augmentcode bot commented Mar 25, 2026

🤖 Augment PR Summary

Summary: This PR updates the search index ranking so schema “health” scores influence result ordering.

Changes:

  • Extended SearchEntry with a health field.
  • Populated search-index entries with health values from explorer directory metadata.
  • Updated make_search() sorting to rank by metadata completeness first, then by higher health, then by path.
  • Expanded unit tests to cover health-driven ordering, tie-breaks, and interactions with metadata completeness.

Technical Notes: Health is used as a sort key during index construction; the serialized JSONL payload format returned by search() remains unchanged (path/title/description only).

🤖 Was this summary useful? React with 👍 or 👎

Copy link

@augmentcode augmentcode bot left a comment

Choose a reason for hiding this comment

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

Review completed. 2 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

std::string path;
std::string title;
std::string description;
std::uint8_t health;
Copy link

Choose a reason for hiding this comment

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

SearchEntry::health is currently left uninitialized for default-constructed entries (e.g., SearchEntry e;), and make_search() reads it during sorting, which can be UB. Consider giving health a default initializer (e.g., std::uint8_t health{0};) so callers that don’t explicitly set it get deterministic behavior.

Severity: medium

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

: "",
directory_entry.defines("health")
? static_cast<std::uint8_t>(
directory_entry.at("health").to_integer())
Copy link

Choose a reason for hiding this comment

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

When converting JSON health to std::uint8_t, out-of-range (or negative) integers will truncate/wrap, which could silently mis-rank results. Consider validating/clamping the integer value before casting so unexpected input can’t distort ordering.

Severity: medium

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 4 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/search/include/sourcemeta/one/search.h">

<violation number="1" location="src/search/include/sourcemeta/one/search.h:25">
P1: `health` has no default member initializer, so a default-constructed `SearchEntry` leaves it indeterminate. Reading it in the `make_search()` comparator is undefined behavior. Initialize it: `std::uint8_t health{0};`.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

std::string path;
std::string title;
std::string description;
std::uint8_t health;
Copy link

@cubic-dev-ai cubic-dev-ai bot Mar 25, 2026

Choose a reason for hiding this comment

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

P1: health has no default member initializer, so a default-constructed SearchEntry leaves it indeterminate. Reading it in the make_search() comparator is undefined behavior. Initialize it: std::uint8_t health{0};.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/search/include/sourcemeta/one/search.h, line 25:

<comment>`health` has no default member initializer, so a default-constructed `SearchEntry` leaves it indeterminate. Reading it in the `make_search()` comparator is undefined behavior. Initialize it: `std::uint8_t health{0};`.</comment>

<file context>
@@ -22,6 +22,7 @@ struct SearchEntry {
   std::string path;
   std::string title;
   std::string description;
+  std::uint8_t health;
 };
 
</file context>
Suggested change
std::uint8_t health;
std::uint8_t health{0};
Fix with Cubic

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Benchmark Index (community)

Details
Benchmark suite Current: 1b87016 Previous: dd5d964 Ratio
Add one schema (0 existing) 20 ms 25 ms 0.80
Add one schema (100 existing) 25 ms 26 ms 0.96
Add one schema (1000 existing) 83 ms 87 ms 0.95
Add one schema (10000 existing) 718 ms 904 ms 0.79
Update one schema (1 existing) 18 ms 20 ms 0.90
Update one schema (101 existing) 26 ms 27 ms 0.96
Update one schema (1001 existing) 85 ms 90 ms 0.94
Update one schema (10001 existing) 724 ms 766 ms 0.95
Cached rebuild (1 existing) 10 ms 11 ms 0.91
Cached rebuild (101 existing) 13 ms 13 ms 1
Cached rebuild (1001 existing) 37 ms 38 ms 0.97
Cached rebuild (10001 existing) 304 ms 311 ms 0.98
Index 100 schemas 131 ms 150 ms 0.87
Index 1000 schemas 1096 ms 1004 ms 1.09
Index 10000 schemas 13885 ms 14287 ms 0.97

This comment was automatically generated by workflow using github-action-benchmark.

@jviotti jviotti merged commit 00a0767 into main Mar 25, 2026
5 checks passed
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Benchmark Index (enterprise)

Details
Benchmark suite Current: 1b87016 Previous: dd5d964 Ratio
Add one schema (0 existing) 21 ms 22 ms 0.95
Add one schema (100 existing) 26 ms 27 ms 0.96
Add one schema (1000 existing) 78 ms 86 ms 0.91
Add one schema (10000 existing) 667 ms 867 ms 0.77
Update one schema (1 existing) 20 ms 20 ms 1
Update one schema (101 existing) 26 ms 26 ms 1
Update one schema (1001 existing) 78 ms 87 ms 0.90
Update one schema (10001 existing) 663 ms 707 ms 0.94
Cached rebuild (1 existing) 11 ms 11 ms 1
Cached rebuild (101 existing) 13 ms 14 ms 0.93
Cached rebuild (1001 existing) 35 ms 38 ms 0.92
Cached rebuild (10001 existing) 271 ms 303 ms 0.89
Index 100 schemas 119 ms 131 ms 0.91
Index 1000 schemas 1098 ms 1120 ms 0.98
Index 10000 schemas 13774 ms 13941 ms 0.99

This comment was automatically generated by workflow using github-action-benchmark.

@jviotti jviotti deleted the search-health branch March 25, 2026 20:27
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.

1 participant