Skip to content

Commit

Permalink
Add convenience functions for parsing the PQ index (#349)
Browse files Browse the repository at this point in the history
* move read_nodes to public, add get_pq_vector and get_num_points

* clang-format

* Match new private var naming convention

* more private (_) fixes

* VID->vid

* VID->vid cpp
  • Loading branch information
PhilipBAdams authored Aug 15, 2023
1 parent 6d4e2bf commit 39b3330
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
25 changes: 14 additions & 11 deletions include/pq_flash_index.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,20 @@ template <typename T, typename LabelT = uint32_t> class PQFlashIndex

DISKANN_DLLEXPORT diskann::Metric get_metric();

//
// node_ids: input list of node_ids to be read
// coord_buffers: pointers to pre-allocated buffers that coords need to copied to. If null, dont copy.
// nbr_buffers: pre-allocated buffers to copy neighbors into
//
// returns a vector of bool one for each node_id: true if read is success, else false
//
DISKANN_DLLEXPORT std::vector<bool> read_nodes(const std::vector<uint32_t> &node_ids,
std::vector<T *> &coord_buffers,
std::vector<std::pair<uint32_t, uint32_t *>> &nbr_buffers);

DISKANN_DLLEXPORT std::vector<std::uint8_t> get_pq_vector(std::uint64_t vid);
DISKANN_DLLEXPORT uint64_t get_num_points();

protected:
DISKANN_DLLEXPORT void use_medoids_data_as_centroids();
DISKANN_DLLEXPORT void setup_thread_data(uint64_t nthreads, uint64_t visited_reserve = 4096);
Expand Down Expand Up @@ -121,17 +135,6 @@ template <typename T, typename LabelT = uint32_t> class PQFlashIndex
// returns region of `node_buf` containing [COORD(T)]
DISKANN_DLLEXPORT T *offset_to_node_coords(char *node_buf);

//
// node_ids: input list of node_ids to be read
// coord_buffers: pointers to pre-allocated buffers that coords need to copied to. If null, dont copy.
// nbr_buffers: pre-allocated buffers to copy neighbors into
//
// returns a vector of bool one for each node_id: true if read is success, else false
//
DISKANN_DLLEXPORT std::vector<bool> read_nodes(const std::vector<uint32_t> &node_ids,
std::vector<T *> &coord_buffers,
std::vector<std::pair<uint32_t, uint32_t *>> &nbr_buffers);

// index info for multi-node sectors
// nhood of node `i` is in sector: [i / nnodes_per_sector]
// offset in sector: [(i % nnodes_per_sector) * max_node_len]
Expand Down
12 changes: 12 additions & 0 deletions src/pq_flash_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1688,6 +1688,18 @@ template <typename T, typename LabelT> char *PQFlashIndex<T, LabelT>::getHeaderB
}
#endif

template <typename T, typename LabelT>
std::vector<std::uint8_t> PQFlashIndex<T, LabelT>::get_pq_vector(std::uint64_t vid)
{
std::uint8_t *pqVec = &this->data[vid * this->_n_chunks];
return std::vector<std::uint8_t>(pqVec, pqVec + this->_n_chunks);
}

template <typename T, typename LabelT> std::uint64_t PQFlashIndex<T, LabelT>::get_num_points()
{
return _num_points;
}

// instantiations
template class PQFlashIndex<uint8_t>;
template class PQFlashIndex<int8_t>;
Expand Down

0 comments on commit 39b3330

Please sign in to comment.