diff --git a/src/pyseekdb/client/client_base.py b/src/pyseekdb/client/client_base.py index b9c104ba..9b30ea27 100644 --- a/src/pyseekdb/client/client_base.py +++ b/src/pyseekdb/client/client_base.py @@ -1504,6 +1504,24 @@ def _fork_database_enabled(self) -> bool: logger.debug(f"db_type: {db_type}, version: {version}") return db_type.lower() == "seekdb" and version >= version_120 + def _refresh_enabled(self) -> bool: + db_type, version = self.detect_db_type_and_version() + version_130 = Version("1.3.0.0") + logger.debug(f"db_type: {db_type}, version: {version}") + return db_type.lower() == "seekdb" and version >= version_130 + + def refresh_index(self) -> None: + """ + Flush async vector index build tasks when supported. + + For unsupported database versions, this method is a no-op to keep + collection-level API calls backward compatible. + """ + if not self._refresh_enabled(): + return + + self._execute("CALL dbms_index_manager.refresh();") + def _get_collection_id(self, collection_name: str) -> str: collection_id_query_sql = f"SELECT COLLECTION_ID FROM `{CollectionNames.sdk_collections_table_name()}` WHERE COLLECTION_NAME = '{collection_name}'" collection_id_query_result = self._execute(collection_id_query_sql) diff --git a/src/pyseekdb/client/collection.py b/src/pyseekdb/client/collection.py index 54982837..db5ce46d 100644 --- a/src/pyseekdb/client/collection.py +++ b/src/pyseekdb/client/collection.py @@ -593,6 +593,19 @@ def hybrid_search( **kwargs, ) + def refresh_index(self) -> None: + """ + Flush async vector index build tasks. + + This executes ``CALL dbms_index_manager.refresh();`` and returns only + after the database completes the refresh procedure. + + Note: + This method is only available for seekdb version 1.3.0.0 or higher. + In 1.2.0.0 and earlier, this method is a no-op. + """ + self._client.refresh_index() + # ==================== Collection Info ==================== def count(self) -> int: diff --git a/tests/integration_tests/test_collection_query.py b/tests/integration_tests/test_collection_query.py index 87ccb9dd..9d2407c1 100644 --- a/tests/integration_tests/test_collection_query.py +++ b/tests/integration_tests/test_collection_query.py @@ -110,6 +110,8 @@ def test_collection_query(self, db_client): # Insert test data self._insert_test_data(db_client, collection_name, dimension=actual_dimension) + collection.refresh_index() + # Test 1: Basic vector similarity query print("\n✅ Testing basic query") # Generate query vector with correct dimension diff --git a/tests/integration_tests/test_collection_v1_compatibility.py b/tests/integration_tests/test_collection_v1_compatibility.py index c1074518..f3257664 100644 --- a/tests/integration_tests/test_collection_v1_compatibility.py +++ b/tests/integration_tests/test_collection_v1_compatibility.py @@ -325,6 +325,8 @@ def test_v1_collection_query(self, db_client): ], ) + collection.refresh_index() + # Query with vector similarity query_vector = [1.0, 2.0, 3.0] results = collection.query( diff --git a/tests/integration_tests/test_offical_case.py b/tests/integration_tests/test_offical_case.py index ced70fdd..afab93a1 100644 --- a/tests/integration_tests/test_offical_case.py +++ b/tests/integration_tests/test_offical_case.py @@ -50,6 +50,8 @@ def _run_official_example(collection): ids=PRODUCT_IDS, ) + collection.refresh_index() + results = collection.query( query_texts=["powerful computer for professional work"], where={ diff --git a/tests/integration_tests/test_sparse_vector_index.py b/tests/integration_tests/test_sparse_vector_index.py index 39638f51..f2285864 100644 --- a/tests/integration_tests/test_sparse_vector_index.py +++ b/tests/integration_tests/test_sparse_vector_index.py @@ -474,6 +474,7 @@ def test_dense_query_still_works(self, db_client): name = _unique_name("query_dense_with_sparse") try: collection, _ids, _ = self._setup_with_data(db_client, name) + collection.refresh_index() results = collection.query( query_embeddings=[1.0, 2.0, 3.0], n_results=3,