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

Conversation

kmrmt
Copy link
Contributor

@kmrmt kmrmt commented Jul 23, 2024

Add new struct and function for exporting NGT::Property to C API.

And I run check program written in C.
I have confirmed blow:

  • insertionRadiusCoefficient(insertion_radius_coefficient in C API) is referred to as EpsilonForCreation in the prf file.
  • searchType (search_type in C API) does not output to prf.
$ cat main.c
#include <NGT/Capi.h>
#include <stdio.h>

void output(NGTPropertyInfo info) {
    printf("accuracy_table\t%s\n", info.accuracy_table);
    printf("batch_size_for_creation\t%d\n", info.batch_size_for_creation);
    printf("build_time_limit\t%f\n", info.build_time_limit);
    printf("database_type\t%d\n", info.database_type);
    printf("dimension\t%d\n", info.dimension);
    printf("distance_type\t%d\n", info.distance_type);
    printf("dynamic_edge_size_base\t%d\n", info.dynamic_edge_size_base);
    printf("dynamic_edge_size_rate\t%d\n", info.dynamic_edge_size_rate);
    printf("edge_size_for_creation\t%d\n", info.edge_size_for_creation);
    printf("edge_size_for_search\t%d\n", info.edge_size_for_search);
    printf("edge_size_limit_for_creation\t%d\n", info.edge_size_limit_for_creation);
    printf("epsilon_for_insertion_order\t%f\n", info.epsilon_for_insertion_order);
    printf("insertion_radius_coefficient(epsilon_for_creation)\t%f\n", info.insertion_radius_coefficient);
    printf("graph_type\t%d\n", info.graph_type);
    printf("incoming_edge\t%d\n", info.incoming_edge);
    printf("truncation_threshold(incremental_edge_size_limit_for_truncation)\t%d\n", info.truncation_threshold);
    printf("index_type\t%d\n", info.index_type);
    printf("max_magnitude\t%f\n", info.max_magnitude);
    printf("n_of_neighbors_for_insertion_order\t%d\n", info.n_of_neighbors_for_insertion_order);
    printf("object_alignment\t%d\n", info.object_alignment);
    printf("object_type\t%d\n", info.object_type);
    printf("outgoing_edge\t%d\n", info.outgoing_edge);
    printf("path_adjustment_interval\t%d\n", info.path_adjustment_interval);
    printf("prefetch_size\t%d\n", info.prefetch_size);
    printf("prefetch_offset\t%d\n", info.prefetch_offset);
    printf("seed_size\t%d\n", info.seed_size);
    printf("seed_type\t%d\n", info.seed_type);
    printf("thread_pool_size\t%d\n", info.thread_pool_size);
    printf("truncation_thread_pool_size\t%d\n", info.truncation_thread_pool_size);
    printf("\n");
    printf("graph_shared_memory_size\t%d\n", info.graph_shared_memory_size);
    printf("tree_shared_memory_size\t%d\n", info.tree_shared_memory_size);
    printf("object_shared_memory_size\t%d\n", info.object_shared_memory_size);
    printf("search_type\t%s\n", info.search_type);
    printf("refinement_object_type\t%d\n", info.refinement_object_type);
}

int main() {
    NGTError error = ngt_create_error_object();
    NGTProperty prop = ngt_create_property(error);
    ngt_set_property_dimension(prop, 128, error);
    ngt_set_property_distance_type_l2(prop, error);
    NGTIndex index = ngt_create_graph_and_tree("./index", prop, error);
    ngt_destroy_property(prop);

    NGTPropertyInfo info = ngt_get_property_info(index, error);
    output(info);

    ngt_save_index(index, "./index", error);
}
$ ./a.out
accuracy_table
batch_size_for_creation 200
build_time_limit        0.000000
database_type   1
dimension       128
distance_type   1
dynamic_edge_size_base  30
dynamic_edge_size_rate  20
edge_size_for_creation  10
edge_size_for_search    0
edge_size_limit_for_creation    5
epsilon_for_insertion_order     0.100000
insertion_radius_coefficient(epsilon_for_creation)      1.100000
graph_type      1
incoming_edge   80
truncation_threshold(incremental_edge_size_limit_for_truncation)        0
index_type      1
max_magnitude   0.000000
n_of_neighbors_for_insertion_order      0
object_alignment        2
object_type     2
outgoing_edge   10
path_adjustment_interval        0
prefetch_size   512
prefetch_offset 2
seed_size       10
seed_type       0
thread_pool_size        32
truncation_thread_pool_size     8

graph_shared_memory_size        -1
tree_shared_memory_size -1
object_shared_memory_size       -1
search_type
refinement_object_type  -1
$ cat ./index/prf
AccuracyTable
BatchSizeForCreation    200
BuildTimeLimit  0
DatabaseType    Memory
Dimension       128
DistanceType    L2
DynamicEdgeSizeBase     30
DynamicEdgeSizeRate     20
EdgeSizeForCreation     10
EdgeSizeForSearch       0
EdgeSizeLimitForCreation        5
EpsilonForCreation      0.1
EpsilonForInsertionOrder        0.1
GraphType       ANNG
IncomingEdge    80
IncrimentalEdgeSizeLimitForTruncation   0
IndexType       GraphAndTree
MaxMagnitude    0
NumberOfNeighborsForInsertionOrder      0
ObjectAlignment False
ObjectType      Float-4
OutgoingEdge    10
PathAdjustmentInterval  0
PrefetchOffset  2
PrefetchSize    512
SeedSize        10
SeedType        None
ThreadPoolSize  32
TruncationThreadPoolSize        8

Signed-off-by: Kosuke Morimoto <ksk@vdaas.org>
@masajiro
Copy link
Member

Thanks!

@masajiro masajiro merged commit 186166c into main Jul 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants