MCPcopy Create free account
hub / github.com/alibaba/zvec / add_with_id_impl

Method add_with_id_impl

src/core/algorithm/flat/flat_streamer.cc:264–302  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

262
263template <size_t BATCH_SIZE>
264int FlatStreamer<BATCH_SIZE>::add_with_id_impl(uint32_t id, const void *query,
265 const IndexQueryMeta &qmeta,
266 Context::Pointer &context) {
267 if (!query || qmeta.dimension() != meta_.dimension() ||
268 qmeta.data_type() != meta_.data_type() ||
269 qmeta.element_size() != meta_.element_size()) {
270 LOG_ERROR(
271 "Failed to add for invalid arguments, query=%p, qmeta(type=%u "
272 "dim=%u size=%u) vs meta(type=%u dim=%u size=%u)",
273 query, qmeta.data_type(), qmeta.dimension(), qmeta.element_size(),
274 meta_.data_type(), meta_.dimension(), meta_.element_size());
275 (*stats_.mutable_discarded_count())++;
276 return IndexError_InvalidArgument;
277 }
278
279 auto *ctx = dynamic_cast<FlatStreamerContext<BATCH_SIZE> *>(context.get());
280 if (!ctx) {
281 LOG_ERROR("Failed to cast FlatStreamerContext");
282 (*stats_.mutable_discarded_count())++;
283 return IndexError_Cast;
284 }
285
286 READ_LOCK_GUARD_DEFER(dump_mutex_, dump_lock);
287
288 if (!dump_lock.try_lock()) {
289 LOG_ERROR("Cannot add vector while dumping index");
290 (*stats_.mutable_discarded_count())++;
291 return IndexError_Unsupported;
292 }
293
294 int ret = entity_.add_vector_with_id(id, query, qmeta.element_size());
295 if (ret != 0) {
296 LOG_ERROR("Failed to add record for %s", IndexError::What(ret));
297 (*stats_.mutable_discarded_count())++;
298 return ret;
299 }
300
301 return 0;
302}
303
304template <size_t BATCH_SIZE>
305int FlatStreamer<BATCH_SIZE>::search_bf_impl(const void *query,

Callers 10

do_build_by_streamerFunction · 0.45
_dense_addMethod · 0.45
_sparse_addMethod · 0.45
add_vecMethod · 0.45
add_sparse_vecMethod · 0.45
TEST_FFunction · 0.45
TEST_FFunction · 0.45
TEST_FFunction · 0.45
TEST_FFunction · 0.45

Calls 7

dimensionMethod · 0.45
data_typeMethod · 0.45
element_sizeMethod · 0.45
getMethod · 0.45
try_lockMethod · 0.45
add_vector_with_idMethod · 0.45

Tested by 4

TEST_FFunction · 0.36
TEST_FFunction · 0.36
TEST_FFunction · 0.36
TEST_FFunction · 0.36