Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduce brute_force index #299

Merged
merged 1 commit into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/vsag/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ extern const char* const INDEX_DISKANN;
extern const char* const INDEX_HNSW;
extern const char* const INDEX_FRESH_HNSW;
extern const char* const INDEX_PYRAMID;
extern const char* const INDEX_BRUTE_FORCE;
extern const char* const DIM;
extern const char* const NUM_ELEMENTS;
extern const char* const IDS;
Expand Down Expand Up @@ -109,4 +110,7 @@ extern const char* const HGRAPH_INIT_CAPACITY;
extern const char* const HGRAPH_BUILD_THREAD_COUNT;
extern const char* const HGRAPH_PRECISE_QUANTIZATION_TYPE;

extern const char* const BRUTE_FORCE_QUANTIZATION_TYPE;
extern const char* const BRUTE_FORCE_IO_TYPE;

} // namespace vsag
6 changes: 3 additions & 3 deletions src/algorithm/hgraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@
}

template <HGraph::InnerSearchMode mode>
HGraph::MaxHeap
MaxHeap
HGraph::search_one_graph(const float* query,
const GraphInterfacePtr& graph,
const FlattenInterfacePtr& flatten,
Expand Down Expand Up @@ -509,7 +509,7 @@
}

void
HGraph::select_edges_by_heuristic(HGraph::MaxHeap& edges,
HGraph::select_edges_by_heuristic(MaxHeap& edges,
uint64_t max_size,
const FlattenInterfacePtr& flatten) {
if (edges.size() < max_size) {
Expand Down Expand Up @@ -730,7 +730,7 @@

tl::expected<void, Error>
HGraph::Deserialize(const BinarySet& binary_set) {
SlowTaskTimer t("hnsw Deserialize");
SlowTaskTimer t("hgraph Deserialize");

Check warning on line 733 in src/algorithm/hgraph.cpp

View check run for this annotation

Codecov / codecov/patch

src/algorithm/hgraph.cpp#L733

Added line #L733 was not covered by tests
if (this->GetNumElements() > 0) {
LOG_ERROR_AND_RETURNS(ErrorType::INDEX_NOT_EMPTY,
"failed to Deserialize: index is not empty");
Expand Down
12 changes: 0 additions & 12 deletions src/algorithm/hgraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,6 @@
namespace vsag {
class HGraph {
public:
struct CompareByFirst {
constexpr bool
operator()(std::pair<float, InnerIdType> const& a,
std::pair<float, InnerIdType> const& b) const noexcept {
return a.first < b.first;
}
};

using MaxHeap = std::priority_queue<std::pair<float, InnerIdType>,
Vector<std::pair<float, InnerIdType>>,
CompareByFirst>;

HGraph(const HGraphParameter& param, const IndexCommonParam& common_param) noexcept;

tl::expected<std::vector<int64_t>, Error>
Expand Down
5 changes: 5 additions & 0 deletions src/constants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const char* const INDEX_DISKANN = "diskann";
const char* const INDEX_HNSW = "hnsw";
const char* const INDEX_FRESH_HNSW = "fresh_hnsw";
const char* const INDEX_PYRAMID = "pyramid";
const char* const INDEX_BRUTE_FORCE = "brute_force";

const char* const DIM = "dim";
const char* const NUM_ELEMENTS = "num_elements";
const char* const IDS = "ids";
Expand Down Expand Up @@ -110,4 +112,7 @@ const char* const HGRAPH_INIT_CAPACITY = "hgraph_init_capacity";
const char* const HGRAPH_BUILD_THREAD_COUNT = "build_thread_count";
const char* const HGRAPH_PRECISE_QUANTIZATION_TYPE = "precise_quantization_type";

const char* const BRUTE_FORCE_QUANTIZATION_TYPE = "quantization_type";
const char* const BRUTE_FORCE_IO_TYPE = "io_type";

}; // namespace vsag
13 changes: 13 additions & 0 deletions src/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include <string>

#include "common.h"
#include "index/brute_force.h"
#include "index/brute_force_parameter.h"
#include "index/diskann.h"
#include "index/diskann_zparameters.h"
#include "index/hgraph_index.h"
Expand Down Expand Up @@ -86,6 +88,17 @@ Engine::CreateIndex(const std::string& origin_name, const std::string& parameter
return tl::unexpected(result.error());
}
return index;
} else if (name == INDEX_BRUTE_FORCE) {
logger::debug("created a brute_force index");
JsonType json;
if (parsed_params.contains(INDEX_PARAM)) {
json = std::move(parsed_params[INDEX_PARAM]);
}
BruteForceParameter param;
param.FromJson(json);
auto brute_force = std::make_shared<BruteForce>(param, index_common_params);

return brute_force;
} else if (name == INDEX_DISKANN) {
// read parameters from json, throw exception if not exists
CHECK_ARGUMENT(parsed_params.contains(INDEX_DISKANN),
Expand Down
Loading
Loading