Skip to content

feat(embeddings): a point layer as the reference of embeddings.similarity (#1720) - #2797

Merged
Mavrick-F merged 2 commits into
opengeos:mainfrom
elpidioassinaturas:feat/1720-similarity-points-layer
Nov 26, 2026
Merged

Mavrick-F merged 2 commits into
opengeos:mainfrom
elpidioassinaturas:feat/1720-similarity-points-layer

Conversation

@elpidioassinaturas

@elpidioassinaturas elpidioassinaturas commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Part of #1720: the leftover of §3.2 that #1876 listed under "Not in this PR", a reference from a point layer.

What it does

embeddings.similarity's "points" takes a point layer's name or id, besides the list of [lon, lat] it takes today. The reference is the mean of the unit embeddings at the layer's points, as for the list.

rustgis-cli run --cmd 'layer.addData={"path":"samples.geojson"}' --cmd 'embeddings.similarity={"dataset":"alphaearth","year":2024,"points":"samples","bbox":[-42.91,-20.78,-42.85,-20.735]}'
  • Which features: the selected ones, or all of them when none is selected, that the definition query keeps: Layer::resolve_rows with Policy::SelectionAndQuery, as geoprocessing tools take a layer (docs/user-guide/analysis.md). The time slider and display filters don't apply, as for tools.
  • Which points: each point of a multipoint is one. They are converted from the system the layer holds its coordinates in (Dataset::lonlat_conversion).
  • The answer has points (those used, as today) and, for a layer, reference: the layer, how many features gave points, and whether a selection (selected) or a definition query (filtered) was applied. They say it was applied, not that it left features out, which the notice says with its counts.
  • When: the layer is found and checked, and its rows (shared, not copied), selection and definition query are taken in similarity_work. Filtering, converting and counting run in the work, before anything is asked of the network, so Cancel and a project change while it runs behave as today.

Never silent

Each is one notice with a count (or an error), and a layer whose every feature is taken says nothing:

  • a selection or definition query that narrows the features (reference points taken from 1 of its 4 features (its selection));
  • a definition query that can't be read, so isn't applied (the map and the tools treat it so too);
  • features without geometry (or an empty one), features that aren't points, points that can't be given in longitude/latitude (a longitude or latitude out of range too, as the list refuses);
  • points outside the area read or on no data: the notice the list has.

Errors, before any request: an unknown layer; a raster, line or polygon layer or a table (with its name and kind); a layer read in place without a selection; an empty layer; a definition query that hides every feature; no usable point (with what was left out); more than 1000 points (the scan ends at the first one past it, so the error doesn't count the rest). A reference with no embedding in the area also says what its layer left out.

Choices

  • A layer read in place holds only the features of the last view, so its selection is taken, and without one it is refused with a way out (select, or Load All Features), as raster.rasterize and a grid's extent layer do. Reading the whole source for at most 1000 points didn't seem worth it, and refusing keeps the command's permissions as they are.
  • The area stays the map's extent or bbox: a layer doesn't change it.
  • A number in points is a layer's id, and a string a name, else an id (Session::layer_id), as "layer" is elsewhere.
  • Approval: the command now has .inputs(…), so a layer named in points is bound and shown when the assistant asks; a list binds no layer.
  • No new parameter, so command-surface.txt is unchanged.

Surfaces

Command line, Python, the assistant and MCP (the parameters' help text), and scripts and models take the new form, as they take the command. The web app and a plugin's command in the app are refused as before. No button exists for the command yet, so there is none to change. The raster is undone as before.

Memory, worked out from the types (not a run of cargo xtask memory, which has no scenario of this command), for a layer whose rows take 64 bytes each plus 24 per field (the sizes of Feature and Value; text and a multipoint's places on top):

  • the rows are shared (0×), and at most 1000 points are kept;
  • nothing more without a selection or a definition query, or with a query that hides no feature (resolve_rows answers Rows::All);
  • with a query that hides some and no selection, resolve_rows holds 8 bytes for each kept row during the scan (up to 24 while that list grows): 0.03× of a layer of 10 fields (0.08× while it grows), and 0.13× (0.38×) of one with no field, the most it can be;
  • with a selection, two copies of it, 16 bytes for each selected feature: 0.05× of a layer of 10 fields and 0.25× of one with no field, when all of it is selected.

Each is freed when the points have been taken, before anything is asked of the network.

Tests

  • a_point_layers_reference_is_its_points_lists: a point and a multipoint, in longitude/latitude and held in UTM 32N, named by name, id and id as text: the list's points to 1e-8° and the same reference; nothing said; what exact approval binds.
  • a_point_layers_selection_and_definition_query_are_its_reference: each alone and together, a feature selected twice, a query that hides none, all, or can't be read.
  • a_point_layer_says_what_its_reference_leaves_out: missing and empty geometry, a line, places out of range; all left out; an empty layer; at the limit and over it.
  • a_reference_layer_that_isnt_one_is_refused: line and raster layers, an unknown name and id, other JSON; a layer read in place, with and without a selection.

Locally (Windows): cargo fmt --check; cargo clippy -p rustgis-engine --all-targets -- -D warnings; cargo xtask layers, test-hygiene and rows. cargo test -p rustgis-engine, after the review round: all pass but four that this change doesn't touch: cog_windows_stand_in_the_level_kept_until_their_tiles_arrive (failed in this full run, passed in the previous one and three times alone), gdal_formats_open_when_gdal_is_installed and files_gdal_reads_are_held_in_their_own_system (this PC's GDAL is 3.7.1; 3.8 is needed) and reload::wrong_geometry_missing_file_and_missing_chosen_table_leave_the_layer_unchanged, which already failed here on main at #1876.

By hand with the branch's rustgis-cli at Viçosa (MG, Brazil), box [-42.91,-20.78,-42.85,-20.735], 2024, a layer of a point, a multipoint of two, a point outside the box and a feature without geometry. The exported GeoTIFFs are byte-identical for the list of the four points, the layer in longitude/latitude (GeoJSON) and the layer in UTM 23S (GeoPackage, EPSG:32723); and for the multipoint selected and the list of its two points.

Searching AlphaEarth needed #2807 (since #1894 every search found no tiles, on main and in 0.8.0), which is now in main. Those runs were made with a local one-line change in its place; they were made again, without it, on a local merge of this branch (73d0e05) and main (132a81c, with #2807), which merges without conflict: embeddings.search finds the box's 2 tiles, and the five GeoTIFFs are byte-identical to the first ones. On that merge cargo test -p rustgis-engine passes but for four: the two GDAL tests and the reload one above, and cloud_optimised_geotiffs_are_read_in_place, which this change doesn't touch and which passed three times alone.

Not tested: the desktop app's window, a layer read in place from a real source (the test sets one on a layer in memory), and the wasm build on this PC (CI's job covers it).

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Similarity searches can now use a point layer by name or ID, as well as a list of coordinates. The search uses selected features when available, otherwise features matching the layer’s definition query. Multipoint features contribute each coordinate.
    • Searches are limited to 1,000 points. Results report layer and feature counts when a layer is used, and note features or coordinates that could not be processed.
  • Documentation
    • Updated the user guide with layer-based similarity examples and details about selection, queries, limits, and in-place layers.

…rity (opengeos#1720)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

embeddings.similarity now accepts point-layer names or IDs as well as coordinate lists. It processes selected or definition-query-matched features, converts point and multipoint geometries to coordinates, and reports processing notes and source-layer metadata.

Changes: Embedding similarity layer references

Layer / File(s) Summary
Reference input and layer resolution
crates/engine/src/cmd/embeddings.rs
The points input accepts a point-layer name or ID and binds named layers for approval. The resolver rejects unsupported layer types and unselected streamed layers.
Layer feature processing
crates/engine/src/cmd/embeddings.rs
The command processes selected features and readable definition queries, converts point and multipoint geometries to coordinates, and reports excluded or unusable features. It refuses empty references and references exceeding 1,000 usable points.
Similarity execution and validation
crates/engine/src/cmd/embeddings.rs, docs/user-guide/web-data.md
The command resolves layer references before reading the tile. Results include the usable point count and, for layer references, source-layer metadata. Tests and documentation cover filtering, limits, errors, and a CLI example.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant Similarity as embeddings.similarity
  participant Resolver as reference_points
  participant Processor as layer_points
  participant TileReader as Tile reader
  Caller->>Similarity: Submit points layer reference
  Similarity->>Resolver: Resolve deferred reference
  Resolver->>Processor: Process selected and query-matched features
  Processor-->>Resolver: Coordinates, notes, and layer metadata
  Resolver-->>Similarity: Reference points
  Similarity->>TileReader: Read tile after reference resolution
  TileReader-->>Similarity: Tile data
  Similarity-->>Caller: Similarity result
Loading

Possibly related issues

Possibly related PRs

  • opengeos/RustGIS#1876: This PR extends the embeddings.similarity command and its existing coordinate-list input.

Suggested reviewers: giswqs

Merge Risk: Minimal · up to 73d0e

The change adds point-layer references to embeddings.similarity, with documented limits and pre-request error handling. No merge-blocking risk was found in the supplied evidence.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: a point layer can now be the reference for embeddings.similarity. It follows the conventional-commit form and matches the raw summary and objectives, which describe la…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description is thorough and covers what the change does, how points and layers are selected, the error and notice behaviour, design choices, memory considerations, the surfaces affected, the tests…
Full details: Title check

Explanation

The title names the main change: a point layer can now be the reference for embeddings.similarity. It follows the conventional-commit form and matches the raw summary and objectives, which describe layer references for the points parameter. The PR number in the title matches the description's reference to #1720.

Full details: Description check

Explanation

The description is thorough and covers what the change does, how points and layers are selected, the error and notice behaviour, design choices, memory considerations, the surfaces affected, the tests added, manual verification with GeoTIFF comparisons, and what was not tested. It follows the template's Summary and Testing sections closely. The UI evidence section is missing its explicit 'No visible UI change.' line, and the Related issue section is filled in only as 'Part of #1720' within the body text rather than under the template heading. These are minor gaps and do not affect the assessment.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit brings points from a layer to the fold,
Through queries and selections, each coordinate is told.
Multipoints share their treasures, one by one,
Notes mark what could not join the run.
Then tiles meet the points, and similarity is done.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: d2f3939a-9f11-491c-a6e6-556666f3d6c7
Commits

Reviewing files that changed from the base of the PR and between 891fb6b and 73d0e05.

Files selected for processing: 2

  • crates/engine/src/cmd/embeddings.rs
  • docs/user-guide/web-data.md

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

Comment thread crates/engine/src/cmd/embeddings.rs Resolved
Comment thread crates/engine/src/cmd/embeddings.rs Resolved
@github-actions

Copy link
Copy Markdown
Contributor

Code review

Scope: 2 files, crates/engine/src/cmd/embeddings.rs and docs/user-guide/web-data.md. I checked the logic against Layer::resolve_rows, Features::geometry, Inputs::single_layer, Session::layer_id, made_or_ran, and GeometryType. Prior review threads: none, so nothing was left out as already raised. I could not build or run the tests here.

Bugs

  • Stale selection indices reported as missing geometry (low confidence). resolve_rows keeps out-of-range selection indices. Features::geometry returns None for them, so they are counted as "features without geometry" and included in "taken from N of M". Selections are usually cleared on edits, so this is rare. Inline comment posted at embeddings.rs:743.

Security

  • None found. The new input is parsed as a layer name or id, and the layer read happens inside the work.

Performance

  • The layer scan counts every feature and reprojects every point, even after the 1000-point limit is passed, before refusing. The exact count is required by the PR text, so this is a trade-off, not a defect. Confidence: low.

Quality

  • reference_points returns a boxed FnOnce with a Taken tuple, and points_layer duplicates the points checks. Nits; readable enough.
  • The hides every selected feature message is also used when the selection is non-empty but its indices are stale. This overlaps the stale-selection item above.

AGENTS.md

  • The layer scan runs on the caller's thread when the command runs directly (medium confidence). made_or_ran runs work(s, p) inline, and the assistant's tools run on the app's frame. A point layer named in points therefore holds the window while every feature is scanned, with no progress or Cancel. Only the network reads are exempted, per the existing comment. Inline comment posted at embeddings.rs:803.
  • Checked and fine: no unwrap/expect in non-test code, no unsafe, notices for every kind of loss with a count, clean-input and lossy-input tests, the command surface unchanged (no new parameter), docs match the code, the definition query and selection policy match the geoprocessing tools, and the Cancel check every 4096 features is documented.

I checked 2 concerns, 0 of them repeated from earlier threads.

Change size

Compared with the base branch: merge base dd3d011 to PR head 703d266.

Measure Value
Files changed 2 (0 added, 2 modified, 0 removed, 0 renamed)
Size before 137.1 KB
Size after 154.7 KB
Total size change +17.6 KB
Path Before After Change
crates/engine/src/cmd/embeddings.rs 70.8 KB 87.3 KB +16.5 KB
docs/user-guide/web-data.md 66.3 KB 67.4 KB +1.1 KB

@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

📖 Docs preview

Commit 73d0e05 from a fork built, but isn't published until a maintainer adds the preview label (once per commit).

…w waits

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

Code review

Reviewed the diff against pr-context/AGENTS.md, the prior review threads, and the surrounding code: Layer::resolve_rows, Dataset and Features (Arc-backed rows), Session::layer_id, lonlat_conversion, and GeometryType. I did not build or run the tests (no shell here), so the claims about test results are the PR author's, not mine.

Bugs: No new bugs found. One earlier concern still applies and is not re-posted: layer_points keeps out-of-range selection indices (per resolve_rows), so Features::geometry returns None for them. They are then counted as "features without geometry" and included in taken, which gives a misleading notice. I confirmed the code is unchanged at that point. Confidence in the bug: medium.

Security: None found. The layer reference goes through Session::layer_id, and no file or command path is opened from the parameter.

Performance: The point-layer scan runs on the assistant's frame with no Cancel. This was raised earlier and answered in the PR (the similarity doc comment states the exemption and its reason), so I left it alone. The definition-query pass in resolve_rows has no Cancel check either; the doc comment on layer_points states this.

Quality (nits, grouped, not posted inline):

  • The answer's reference.filtered is true whenever a definition query is present and readable, even when it hides nothing. The PR body says it means the query "narrowed" the features. web-data.md matches the code, so only the PR body is off. Confidence: high.
  • A malformed points list now reports "points is a list of [longitude, latitude] in degrees, or a point layer's name or id". That hides the list-specific cause. A string holding a JSON list gets "no layer named '[[…]]'". Confidence: medium.
  • The doc sentence on layer_points ("the definition query is one pass that doesn't ([…])") is truncated. Confidence: high.

AGENTS.md:

  • "Size for real data" asks the PR to state what a change holding layer data comes to as a multiple of the layer. The PR body says only "the layer's rows are shared". Sharing is accurate, since Features is Arc-backed, but the kept-row index vector from resolve_rows (up to 8 bytes per feature) and the selection clone are not quantified. Confidence: medium-low.
  • I checked the other rules the change touches and found no breaks: the surfaces list in the PR body, command ids (none added), command-surface.txt (no new parameter), IN_BACKGROUND membership, and wasm (the new code uses only items that exist on wasm, and the browser branch still returns IN_THE_BROWSER).

No inline comments were posted. The earlier threads on this PR: 2 concerns left alone (the UI-thread scan, which the author answered, and the out-of-range index miscount, which is still present).

Change size

Compared: the whole PR against main (merge base dd3d011 to PR head 73d0e05).

Measure Value
Files changed 2 (added 0, modified 2, removed 0, renamed 0)
Size before 137.1 KB
Size after 155.5 KB
Total size change +18.4 KB
Path Before After Change
crates/engine/src/cmd/embeddings.rs 70.8 KB 88.1 KB +17.3 KB
docs/user-guide/web-data.md 66.3 KB 67.4 KB +1.1 KB

@elpidioassinaturas
elpidioassinaturas marked this pull request as ready for review November 25, 2026 05:05
Comment thread crates/engine/src/cmd/embeddings.rs Resolved
Comment thread crates/engine/src/cmd/embeddings.rs Resolved
@github-actions

Copy link
Copy Markdown
Contributor

Code review

Reviewed PR #2797 (embeddings.similarity takes a point layer as its reference), the diff, and the related code in crates/map/src/rows.rs, crates/data/src/rows.rs and crates/data/src/lib.rs. Two earlier review threads were left alone: the background-thread concern is answered by a documented exemption in the similarity doc comment, and the out-of-range selection-index concern is answered by the author. I checked the second one: resolve_rows does keep out-of-range indices (rows.rs:53), so it depends on the author's claim that selections are always normalised. I did not find evidence against that claim.

Bugs

  • None found in the new code. The notices, error paths and cancel checks match the tests and the AGENTS.md rules I checked. Confidence: moderate, since I could not build or run the tests here.

Security

  • None found. Layer names and other user text only appear in error and notice strings. Confidence: high.

Performance

  • Index vector for a definition query (embeddings.rs:719). When a query hides rows and nothing is selected, resolve_rows allocates one usize per kept row before the scan. On a layer of tens of millions of features that is hundreds of MB transiently, and the 1000-point limit does not bound it. The PR's memory note does not give this as a multiple of the layer, which AGENTS.md asks for. Confidence: medium-low that it matters in practice; high that the PR description is incomplete.

Quality

  • filtered in the answer (embeddings.rs:720). It is true whenever a readable query was given, not when the query narrowed the rows. A query like n > 0 reports "filtered": true with nothing removed, which conflicts with the PR text. Confidence: high.
  • Nit, not posted: the "can't be given in longitude/latitude" notice also counts out-of-range coordinates in a longitude/latitude layer (for example latitude 95), where "can't be given" is slightly misleading. Confidence: high. Wording only.

AGENTS.md

  • None found. The background-thread exemption is stated in the similarity doc comment with its reason, the new code has no unwrap, expect or panic, and the command surface and parameter keys are unchanged. Confidence: moderate.

Change size

Compared with the base branch (merge base dd3d011 to PR head 73d0e05).

Measure Value
Files changed 2 (added 0, modified 2, removed 0, renamed 0)
Size before 137.1 KB
Size after 155.5 KB
Total size change +18.4 KB
Path Before After Change
crates/engine/src/cmd/embeddings.rs 70.8 KB 88.1 KB +17.3 KB
docs/user-guide/web-data.md 66.3 KB 67.4 KB +1.1 KB

@Mavrick-F
Mavrick-F added this pull request to the merge queue Nov 26, 2026
Merged via the queue into opengeos:main with commit 36b8e7c Nov 26, 2026
30 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.

3 participants