ljyss9 commented on code in PR #483:
URL: https://github.com/apache/paimon-cpp/pull/483#discussion_r4534785517


##########
src/paimon/core/io/file_index_evaluator.cpp:
##########
@@ -291,14 +292,47 @@ Result<std::shared_ptr<ScoredFileIndexResult>> 
FileIndexEvaluator::EvaluateVecto
     const std::shared_ptr<VectorSearch>& vector_search,
     const std::shared_ptr<DataFilePathFactory>& path_factory,
     const std::shared_ptr<DataFileMeta>& file_meta, const 
std::shared_ptr<FileSystem>& file_system,
-    const std::shared_ptr<MemoryPool>& pool) {
+    const std::shared_ptr<MemoryPool>& pool, const std::shared_ptr<Cache>& 
cache) {
     PAIMON_ASSIGN_OR_RAISE(std::shared_ptr<InputStream> input_stream,
                            
ExtractIndexInputStream(/*only_use_embedding_index=*/false, path_factory,
                                                    file_meta, file_system));
-    PAIMON_ASSIGN_OR_RAISE(std::vector<std::shared_ptr<FileIndexReader>> 
readers,
-                           OpenSearchReaders(data_schema, 
vector_search->field_name, options,
-                                             file_meta, input_stream, pool));
-    return ExecuteVectorSearch(readers, vector_search);
+    auto open_reader = [&]() -> Result<std::shared_ptr<FileIndexReader>> {
+        PAIMON_ASSIGN_OR_RAISE(std::vector<std::shared_ptr<FileIndexReader>> 
readers,
+                               OpenSearchReaders(data_schema, 
vector_search->field_name, options,
+                                                 file_meta, input_stream, 
pool));
+        return GetVectorSearchReader(readers, vector_search->field_name);
+    };
+    std::string uri;
+    if (cache && input_stream) {
+        auto uri_result = input_stream->GetUri();
+        if (uri_result.ok()) {
+            uri = std::move(uri_result).value();
+        }
+    }
+    if (uri.empty()) {
+        PAIMON_ASSIGN_OR_RAISE(std::shared_ptr<FileIndexReader> reader, 
open_reader());
+        return reader->VisitVectorSearch(vector_search);
+    }
+    std::shared_ptr<arrow::Field> field = 
data_schema->GetFieldByName(vector_search->field_name);
+    if (!field) {
+        return Status::Invalid(fmt::format("Search field '{}' does not exist 
in data schema",
+                                           vector_search->field_name));
+    }
+    auto key = CacheKey::ForIndexReader(uri, vector_search->field_name);
+    PAIMON_ASSIGN_OR_RAISE(
+        std::shared_ptr<CacheValue> value,
+        cache->Get(
+            key, [&](const std::shared_ptr<CacheKey>&) -> 
Result<std::shared_ptr<CacheValue>> {
+                PAIMON_ASSIGN_OR_RAISE(int64_t length, input_stream->Length());

Review Comment:
   Cache weight no longer uses the serialized index file size. Each cached 
reader owns an independent pool, and the estimate is `sizeof(CachedIndexReader) 
+ pool->CurrentUsage()` after the temporary loading evaluator has been 
destroyed. 



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to