@@ -177,7 +177,7 @@ class Rdb_vector_iterator : public faiss::InvertedListsIterator {
177177 public:
178178 Rdb_vector_iterator (Rdb_faiss_inverted_list_context *context,
179179 Index_id index_id, rocksdb::ColumnFamilyHandle &cf,
180- const uint code_size, size_t list_id)
180+ const Rdb_key_def &kd, uint code_size, size_t list_id)
181181 : m_context(context),
182182 m_index_id (index_id),
183183 m_list_id(list_id),
@@ -190,7 +190,7 @@ class Rdb_vector_iterator : public faiss::InvertedListsIterator {
190190 write_inverted_list_key (upper_key_writer, index_id, list_id + 1 );
191191 m_iterator_upper_bound_key.PinSelf (upper_key_writer.to_slice ());
192192 m_iterator = rdb_tx_get_iterator (
193- context->m_thd , cf, /* skip_bloom_filter */ true ,
193+ context->m_thd , cf, kd, /* skip_bloom_filter */ true ,
194194 m_iterator_lower_bound_key, m_iterator_upper_bound_key,
195195 /* snapshot */ nullptr , TABLE_TYPE::USER_TABLE);
196196 m_iterator->SeekToFirst ();
@@ -270,8 +270,11 @@ class Rdb_vector_iterator : public faiss::InvertedListsIterator {
270270class Rdb_faiss_inverted_list : public faiss ::InvertedLists {
271271 public:
272272 Rdb_faiss_inverted_list (Index_id index_id, rocksdb::ColumnFamilyHandle &cf,
273- uint nlist, uint code_size)
274- : InvertedLists(nlist, code_size), m_index_id(index_id), m_cf(cf) {
273+ const Rdb_key_def &kd, uint nlist, uint code_size)
274+ : InvertedLists(nlist, code_size),
275+ m_index_id (index_id),
276+ m_cf(cf),
277+ m_kd(kd) {
275278 use_iterator = true ;
276279 }
277280 ~Rdb_faiss_inverted_list () override = default ;
@@ -293,7 +296,7 @@ class Rdb_faiss_inverted_list : public faiss::InvertedLists {
293296 return new Rdb_vector_iterator (
294297 reinterpret_cast <Rdb_faiss_inverted_list_context *>(
295298 inverted_list_context),
296- m_index_id, m_cf, code_size, list_no);
299+ m_index_id, m_cf, m_kd, code_size, list_no);
297300 }
298301
299302 const uint8_t *get_codes (size_t list_no) const override {
@@ -353,14 +356,18 @@ class Rdb_faiss_inverted_list : public faiss::InvertedLists {
353356 private:
354357 Index_id m_index_id;
355358 rocksdb::ColumnFamilyHandle &m_cf;
359+ const Rdb_key_def &m_kd;
356360};
357361
358362class Rdb_vector_index_ivf : public Rdb_vector_index {
359363 public:
360364 Rdb_vector_index_ivf (const FB_vector_index_config index_def,
361365 std::shared_ptr<rocksdb::ColumnFamilyHandle> cf_handle,
362- const Index_id index_id)
363- : m_index_id{index_id}, m_index_def{index_def}, m_cf_handle{cf_handle} {}
366+ const Rdb_key_def &kd, const Index_id index_id)
367+ : m_index_id{index_id},
368+ m_index_def{index_def},
369+ m_cf_handle{cf_handle},
370+ m_kd{kd} {}
364371
365372 virtual ~Rdb_vector_index_ivf () override = default ;
366373
@@ -446,8 +453,8 @@ class Rdb_vector_index_ivf : public Rdb_vector_index {
446453 for (std::size_t i = 0 ; i < m_list_size_stats.size (); i++) {
447454 std::size_t list_size = 0 ;
448455 Rdb_faiss_inverted_list_context context (thd);
449- Rdb_vector_iterator vector_iter (&context, m_index_id, *m_cf_handle,
450- m_index_l2->code_size , i);
456+ Rdb_vector_iterator vector_iter (&context, m_index_id, *m_cf_handle. get () ,
457+ m_kd, m_index_l2->code_size , i);
451458 while (vector_iter.is_available ()) {
452459 uint rtn = vector_iter.get_pk_and_codes (pk, codes);
453460 if (rtn) {
@@ -524,7 +531,8 @@ class Rdb_vector_index_ivf : public Rdb_vector_index {
524531
525532 // create inverted list
526533 m_inverted_list = std::make_unique<Rdb_faiss_inverted_list>(
527- m_index_id, *m_cf_handle, m_index_l2->nlist , m_index_l2->code_size );
534+ m_index_id, *m_cf_handle.get (), m_kd, m_index_l2->nlist ,
535+ m_index_l2->code_size );
528536 m_index_l2->replace_invlists (m_inverted_list.get ());
529537 m_index_ip->replace_invlists (m_inverted_list.get ());
530538
@@ -589,6 +597,7 @@ class Rdb_vector_index_ivf : public Rdb_vector_index {
589597 Index_id m_index_id;
590598 FB_vector_index_config m_index_def;
591599 std::shared_ptr<rocksdb::ColumnFamilyHandle> m_cf_handle;
600+ const Rdb_key_def &m_kd;
592601 std::atomic<uint> m_hit{0 };
593602 std::unique_ptr<faiss::IndexFlatL2> m_quantizer;
594603 std::unique_ptr<faiss::IndexIVF> m_index_l2;
@@ -683,13 +692,14 @@ uint create_vector_index(Rdb_cmd_srv_helper &cmd_srv_helper,
683692 const std::string &db_name,
684693 const FB_vector_index_config index_def,
685694 std::shared_ptr<rocksdb::ColumnFamilyHandle> cf_handle,
695+ const Rdb_key_def &kd,
686696 const Index_id index_id,
687697 std::unique_ptr<Rdb_vector_index> &index) {
688698 if (index_def.type () == FB_VECTOR_INDEX_TYPE::FLAT ||
689699 index_def.type () == FB_VECTOR_INDEX_TYPE::IVFFLAT ||
690700 index_def.type () == FB_VECTOR_INDEX_TYPE::IVFPQ) {
691701 index =
692- std::make_unique<Rdb_vector_index_ivf>(index_def, cf_handle, index_id);
702+ std::make_unique<Rdb_vector_index_ivf>(index_def, cf_handle, kd, index_id);
693703 } else {
694704 assert (false );
695705 return HA_ERR_UNSUPPORTED;
@@ -700,14 +710,11 @@ uint create_vector_index(Rdb_cmd_srv_helper &cmd_srv_helper,
700710#else
701711
702712// dummy implementation for non-fbvectordb builds
703- uint create_vector_index (Rdb_cmd_srv_helper &cmd_srv_helper [[maybe_unused]],
704- const std::string &db_name [[maybe_unused]],
705- const FB_vector_index_config index_def
706- [[maybe_unused]],
707- std::shared_ptr<rocksdb::ColumnFamilyHandle> cf_handle
708- [[maybe_unused]],
709- const Index_id index_id [[maybe_unused]],
710- std::unique_ptr<Rdb_vector_index> &index) {
713+ uint create_vector_index (Rdb_cmd_srv_helper &, const std::string &,
714+ const FB_vector_index_config,
715+ std::shared_ptr<rocksdb::ColumnFamilyHandle>,
716+ const Rdb_key_def, const Index_id,
717+ std::unique_ptr<Rdb_vector_index> &) {
711718 index = nullptr ;
712719 return HA_ERR_UNSUPPORTED;
713720}
0 commit comments