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

Export NGT Property to C API and add struct and function to get it #166

Merged
merged 1 commit into from
Jul 23, 2024
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
64 changes: 64 additions & 0 deletions lib/NGT/Capi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,70 @@ bool ngt_set_property_distance_type_inner_product(NGTProperty prop, NGTError err
return ngt_set_property_distance_type(prop, NGT::Index::Property::DistanceType::DistanceTypeInnerProduct, error);
}

NGTPropertyInfo ngt_get_property_info(NGTIndex index, NGTError error) {
NGT::Property prop;
try {
static_cast<NGT::Index*>(index)->getProperty(prop);
} catch(std::exception &err) {
std::stringstream ss;
ss << "Capi : " << __FUNCTION__ << "() : Error: " << err.what();
operate_error_string_(ss, error);
NGTPropertyInfo err_val = {0};
return err_val;
}
NGTPropertyInfo info = {
prop.dimension,
prop.threadPoolSize,
prop.objectType,
prop.distanceType,
prop.indexType,
prop.databaseType,
prop.objectAlignment,
prop.pathAdjustmentInterval,
#ifdef NGT_SHARED_MEMORY_ALLOCATOR
prop.graphSharedMemorySize,
prop.treeSharedMemorySize,
prop.objectSharedMemorySize,
#else
-1,
-1,
-1,
#endif
prop.prefetchOffset,
prop.prefetchSize,
prop.accuracyTable.c_str(),
prop.searchType.c_str(),
#ifdef NGT_INNER_PRODUCT
prop.maxMagnitude,
#else
-1,
#endif
prop.nOfNeighborsForInsertionOrder,
prop.epsilonForInsertionOrder,
#ifdef NGT_REFINEMENT
prop.refinementObjectType,
#else
-1,
#endif
prop.truncationThreshold,
prop.edgeSizeForCreation,
prop.edgeSizeForSearch,
prop.edgeSizeLimitForCreation,
prop.insertionRadiusCoefficient,
prop.seedSize,
prop.seedType,
prop.truncationThreadPoolSize,
prop.batchSizeForCreation,
prop.graphType,
prop.dynamicEdgeSizeBase,
prop.dynamicEdgeSizeRate,
prop.buildTimeLimit,
prop.outgoingEdge,
prop.incomingEdge
};
return info;
}

NGTObjectDistances ngt_create_empty_results(NGTError error) {
try{
return static_cast<NGTObjectDistances>(new NGT::ObjectDistances());
Expand Down
39 changes: 39 additions & 0 deletions lib/NGT/Capi.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,43 @@ typedef struct {
size_t indegreeHistogramSize;
} NGTGraphStatistics;

typedef struct {
int dimension;
int thread_pool_size;
int object_type;
int distance_type;
int index_type;
int database_type;
int object_alignment;
int path_adjustment_interval;
int graph_shared_memory_size;
int tree_shared_memory_size;
int object_shared_memory_size;
int prefetch_offset;
int prefetch_size;
const char* accuracy_table;
const char* search_type;
float max_magnitude;
int n_of_neighbors_for_insertion_order;
float epsilon_for_insertion_order;
int refinement_object_type;
int16_t truncation_threshold;
int16_t edge_size_for_creation;
int16_t edge_size_for_search;
int16_t edge_size_limit_for_creation;
double insertion_radius_coefficient;
int16_t seed_size;
int seed_type;
int16_t truncation_thread_pool_size;
int16_t batch_size_for_creation;
int graph_type;
int16_t dynamic_edge_size_base;
int16_t dynamic_edge_size_rate;
float build_time_limit;
int16_t outgoing_edge;
int16_t incoming_edge;
} NGTPropertyInfo;

NGTIndex ngt_open_index(const char *, NGTError);

NGTIndex ngt_open_index_as_read_only(const char *, NGTError);
Expand Down Expand Up @@ -185,6 +222,8 @@ bool ngt_set_property_distance_type_normalized_cosine(NGTProperty, NGTError);

bool ngt_set_property_distance_type_inner_product(NGTProperty, NGTError);

NGTPropertyInfo ngt_get_property_info(NGTIndex, NGTError);

NGTObjectDistances ngt_create_empty_results(NGTError);

bool ngt_search_index(NGTIndex, double*, int32_t, size_t, float, float, NGTObjectDistances, NGTError);
Expand Down