HappenLee commented on code in PR #54276:
URL: https://github.com/apache/doris/pull/54276#discussion_r2286927835


##########
be/src/olap/rowset/segment_v2/ann_index/ann_index_reader.cpp:
##########
@@ -0,0 +1,220 @@
+// 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.
+
+#include "ann_index_reader.h"
+
+#include <cstddef>
+#include <memory>
+
+#include "ann_index_iterator.h"
+#include "common/config.h"
+#include "io/io_common.h"
+#include "olap/rowset/segment_v2/ann_index/ann_index.h"
+#include "olap/rowset/segment_v2/ann_index/ann_search_params.h"
+#include "olap/rowset/segment_v2/ann_index/faiss_ann_index.h"
+#include "olap/rowset/segment_v2/index_file_reader.h"
+#include "olap/rowset/segment_v2/inverted_index_compound_reader.h"
+#include "runtime/runtime_state.h"
+#include "util/doris_metrics.h"
+#include "util/once.h"
+#include "util/runtime_profile.h"
+
+namespace doris::segment_v2 {
+#include "common/compile_check_begin.h"
+void AnnIndexReader::update_result(const IndexSearchResult& search_result,
+                                   std::vector<float>& distance, 
roaring::Roaring& roaring) {
+    DCHECK(search_result.distances != nullptr);
+    DCHECK(search_result.roaring != nullptr);
+    size_t limit = search_result.roaring->cardinality();
+    // Use search result to update distance and row_id
+    distance.resize(limit);
+    for (size_t i = 0; i < limit; ++i) {
+        distance[i] = search_result.distances[i];
+    }
+    roaring = *search_result.roaring;
+}
+
+AnnIndexReader::AnnIndexReader(const TabletIndex* index_meta,
+                               std::shared_ptr<IndexFileReader> 
index_file_reader)
+        : _index_meta(*index_meta), _index_file_reader(index_file_reader) {
+    const auto index_properties = _index_meta.properties();
+    auto it = index_properties.find("index_type");
+    DCHECK(it != index_properties.end());
+    _index_type = it->second;
+    it = index_properties.find("metric_type");
+    DCHECK(it != index_properties.end());
+    _metric_type = string_to_metric(it->second);
+}
+
+Status AnnIndexReader::new_iterator(std::unique_ptr<IndexIterator>* iterator) {
+    *iterator = AnnIndexIterator::create_unique(shared_from_this());
+    return Status::OK();
+}
+
+Status AnnIndexReader::load_index(io::IOContext* io_ctx) {
+    return _load_index_once.call([&]() {
+        DorisMetrics::instance()->ann_index_load_cnt->increment(1);
+
+        try {
+            RETURN_IF_ERROR(
+                    
_index_file_reader->init(config::inverted_index_read_buffer_size, io_ctx));
+            Result<std::unique_ptr<DorisCompoundReader, DirectoryDeleter>> 
compound_dir;
+            compound_dir = _index_file_reader->open(&_index_meta, io_ctx);
+            if (!compound_dir.has_value()) {
+                return Status::IOError("Failed to open index file: {}",
+                                       compound_dir.error().to_string());
+            }
+            _vector_index = std::make_unique<FaissVectorIndex>();
+            _vector_index->set_metric(_metric_type);
+            RETURN_IF_ERROR(_vector_index->load(compound_dir->get()));
+        } catch (CLuceneError& err) {

Review Comment:
   why ann index throw `CLuceneError`



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to