You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@paimon.apache.org by "JingsongLi (via GitHub)" <gi...@apache.org> on 2026/10/09 13:47:58 UTC
[PR] [python] Execute local vector search through Rust core [paimon]
JingsongLi opened a new pull request, #10476:
URL: https://github.com/apache/paimon/pull/10476
## Purpose
Use Rust core for the local vector-search capabilities PyPaimon already supports on REST tables. Single-vector searches delegate for DE and configured PK vector indexes; batch delegation uses PyPaimon's existing DE result API.
Depends on https://github.com/apache/paimon-rust/pull/1087. This PR is Draft until that binding API is available on Rust main. Native CI continues to install Apache paimon-rust main.
## Changes
- Reuse the resolved Native table and REST FileIO context for local search. Rust owns planning, scalar pre-filtering, index evaluation, raw scoring, Top-K and refinement.
- Convert Native metadata into the existing scored global-row-ID and PK physical-position result classes. PK split bytes retain their source snapshot, deletion metadata, ranges and aligned scores.
- Keep optional-backend fallback, explicit disable, query-auth rejection, fork-safety errors and unsupported I/O contexts consistent with other Native readers.
- Align the Python reader with Java `AbstractDataEvolutionVectorRead.prepareSplits`: when a scalar filter cannot be evaluated by an index, search its covered ranges from the data rather than silently excluding those rows. Validate persisted metrics for every rerouted shard.
- Serialize VECTOR types exactly as Java does, encoding nullability in the `type` string and omitting the extra `nullable` member that blocked Native REST loading.
- Update a stale PK sharding test to reflect the already merged Native sorted-index planning ownership.
## Tests
Real REST regression cases compare Python and Native single/batch results for all three metrics, scalar/partition predicates, indexed and uncovered ranges, FAST/FULL/DETAIL, empty results, Java-produced PK indexes, refinement, result materialization, snapshot-pinned scan/read reuse, mixed metric failures and fallback behavior.
Classic vector regression suites, Native read/write/update/commit regressions, flake8 and Python 3.6 syntax checks are included in local verification. Final Native suite results will be recorded below when the run completes.
## Scope
This enables existing local search APIs. Distributed Ray scan/read and PyPaimon's PK batch API retain their current behavior. No new dependencies or CI ref pins are added.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [python] Execute local vector search through Rust core [paimon]
Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi merged PR #10476:
URL: https://github.com/apache/paimon/pull/10476
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [python] Execute local vector search through Rust core [paimon]
Posted by "leaves12138 (via GitHub)" <gi...@apache.org>.
leaves12138 commented on code in PR #10476:
URL: https://github.com/apache/paimon/pull/10476#discussion_r4231176134
##########
paimon-python/pypaimon/table/source/native_vector_search.py:
##########
@@ -0,0 +1,93 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""Local vector search through the Rust core Scan -> Plan -> Read path."""
+
+import logging
+
+from pypaimon.catalog.table_query_auth import reject_search_under_query_auth
+from pypaimon.globalindex.vector_search_result import DictBasedScoredIndexResult
+from pypaimon.read.native_plan import (
+ _catalog_metastore, _native_table, _partition_fields, _predicate_to_native,
+ _raise_if_native_fork_safety_error, native_method_available)
+from pypaimon.read.split_serializer import deserialize_split_v1
+from pypaimon.table.source.primary_key_scored_result import (
+ PrimaryKeyScoredResult, PrimaryKeySearchPosition)
+
+logger = logging.getLogger(__name__)
+
+
+def try_native_vector_search(builder, queries, batch=False):
+ """Return existing Python result types, or None to use the Python reader.
+
+ Search, scalar filtering, refinement and physical-position selection all
+ belong to Rust core. Python only converts the scored result metadata.
+ """
+ table = builder._table
+ reject_search_under_query_auth(table)
+ try:
+ native_enabled = getattr(table.options, 'native_read_enabled', None)
+ if not callable(native_enabled) or not native_enabled():
+ return None
+ loader = getattr(getattr(table, 'catalog_environment', None), 'catalog_loader', None)
+ if loader is None or _catalog_metastore(loader) != 'rest':
+ return None
+ context_fn = getattr(loader, 'context', None)
+ if not callable(context_fn):
+ return None
+ context = context_fn()
+ if any(getattr(context, attr, None) is not None for attr in (
+ 'hadoop_conf', 'prefer_io_loader', 'fallback_io_loader')):
+ return None
+ # Python's batch reader currently supports only global row-ID results.
+ if batch and builder._is_primary_key_vector_search():
+ return None
+ method = 'new_batch_vector_search_builder' if batch else 'new_vector_search_builder'
+ if not native_method_available('Table', method):
+ return None
+ native = getattr(_native_table(table), method)()
+ if builder._vector_column is not None:
+ native.with_vector_column(builder._vector_column.name)
+ native.with_limit(builder._limit).with_options(builder._options)
+ if builder._filter is not None:
+ native.with_filter(_predicate_to_native(builder._filter))
Review Comment:
[P2] Preserve global-index.filter.refine-from-data semantics during delegation
With an inexact scalar-index answer, Java and this PR's classic reader exclude candidates when `global-index.filter.refine-from-data=false`. The delegated core path instead reads the data to build an exact allow-list, ignoring that switch and changing the existing public API's result and I/O behavior just by enabling Native reading.
On a real REST table with a BTREE index on `name`, an IVF-flat vector index, `name LIKE '%zeta%'`, and limit 1, classic returns 0 hits with refinement disabled whereas the new Native path returns 1 (batch: `[0, 0]` versus `[1, 1]`). All FAST/FULL/DETAIL cases reproduce it; enabled-refinement controls agree. Please require the companion core fix, or decline Native delegation for these unsupported refinement semantics.
##########
paimon-python/pypaimon/table/source/native_vector_search.py:
##########
@@ -0,0 +1,93 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""Local vector search through the Rust core Scan -> Plan -> Read path."""
+
+import logging
+
+from pypaimon.catalog.table_query_auth import reject_search_under_query_auth
+from pypaimon.globalindex.vector_search_result import DictBasedScoredIndexResult
+from pypaimon.read.native_plan import (
+ _catalog_metastore, _native_table, _partition_fields, _predicate_to_native,
+ _raise_if_native_fork_safety_error, native_method_available)
+from pypaimon.read.split_serializer import deserialize_split_v1
+from pypaimon.table.source.primary_key_scored_result import (
+ PrimaryKeyScoredResult, PrimaryKeySearchPosition)
+
+logger = logging.getLogger(__name__)
+
+
+def try_native_vector_search(builder, queries, batch=False):
+ """Return existing Python result types, or None to use the Python reader.
+
+ Search, scalar filtering, refinement and physical-position selection all
+ belong to Rust core. Python only converts the scored result metadata.
+ """
+ table = builder._table
+ reject_search_under_query_auth(table)
+ try:
+ native_enabled = getattr(table.options, 'native_read_enabled', None)
+ if not callable(native_enabled) or not native_enabled():
+ return None
+ loader = getattr(getattr(table, 'catalog_environment', None), 'catalog_loader', None)
+ if loader is None or _catalog_metastore(loader) != 'rest':
+ return None
+ context_fn = getattr(loader, 'context', None)
+ if not callable(context_fn):
+ return None
+ context = context_fn()
+ if any(getattr(context, attr, None) is not None for attr in (
+ 'hadoop_conf', 'prefer_io_loader', 'fallback_io_loader')):
+ return None
+ # Python's batch reader currently supports only global row-ID results.
+ if batch and builder._is_primary_key_vector_search():
+ return None
+ method = 'new_batch_vector_search_builder' if batch else 'new_vector_search_builder'
+ if not native_method_available('Table', method):
+ return None
+ native = getattr(_native_table(table), method)()
+ if builder._vector_column is not None:
+ native.with_vector_column(builder._vector_column.name)
+ native.with_limit(builder._limit).with_options(builder._options)
+ if builder._filter is not None:
+ native.with_filter(_predicate_to_native(builder._filter))
+ if builder._partition_filter is not None:
+ native.with_partition_filter(_predicate_to_native(builder._partition_filter))
+ if batch:
+ native.with_query_vectors(queries)
+ results = native.execute_batch_local()
+ return [DictBasedScoredIndexResult(result.row_ids()) for result in results]
+ native.with_query_vector(queries)
+ result = native.execute_local()
Review Comment:
[P1] Do not enable Native DE filtering before matching Java's raw fallback
For a scalar predicate that cannot be evaluated by a scalar index, the classic reader added in this PR correctly follows Java `AbstractDataEvolutionVectorRead.prepareSplits`: it reroutes vector-index-covered ranges to raw scoring. This new delegation bypasses that policy and accepts an empty Native ANN result as a successful result, so the exception fallback does not help.
Using a real REST IVF-flat index with four clusters, `ivf.nprobe=1`, query `[0, 0]`, limit 3, and `id >= 100` without an `id` scalar index, the classic path returns 3 hits while the new public Native path returns 0. This reproduces for single/batch and FAST/FULL/DETAIL; probing all four clusters recovers the three Native hits. The core issue is detailed on apache/paimon-rust#1087. Please land the Java-equivalent core routing before enabling these filtered searches, or keep unsupported cases on the classic lane until then.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [python] Execute local vector search through Rust core [paimon]
Posted by "JingsongLi (via GitHub)" <gi...@apache.org>.
JingsongLi commented on PR #10476:
URL: https://github.com/apache/paimon/pull/10476#issuecomment-6092428079
@copilot 解决此分支上的合并冲突。
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@paimon.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org