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

Add C API #121

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,4 @@ add_custom_target (version
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/GenerateVersionHeader.cmake
)
add_dependencies (vsag version)
add_dependencies (vsag_static version)
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ include_directories (vsag-cmake-example PRIVATE ${vsag_SOURCE_DIR}/include)
# compile executable and link to vsag
add_executable (vsag-cmake-example src/main.cpp)
target_link_libraries (vsag-cmake-example PRIVATE vsag)
# If you want static linking
# target_link_libraries (vsag-cmake-example PRIVATE vsag_static)

# add dependency
add_dependencies (vsag-cmake-example vsag)
Expand Down
85 changes: 85 additions & 0 deletions include/vsag/c.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// Copyright 2023 Greptime Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

#ifdef __cplusplus
extern "C" {
#endif

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

#ifndef VSAG_MAX_ERROR_MESSAGE_LENGTH
#define VSAG_MAX_ERROR_MESSAGE_LENGTH 256
#endif

typedef struct CError {
int type_;
char message[VSAG_MAX_ERROR_MESSAGE_LENGTH];
} CError;

CError*
new_error(int type_, const char* msg);
void
free_error(const CError*);

const CError*
create_index(const char* in_index_type,
const char* in_parameters,

void** out_index_ptr);

const CError*
build_index(void* in_index_ptr,
size_t in_num_vectors,
size_t in_dim,
const int64_t* in_ids,
const float* in_vectors,

const int64_t** out_failed_ids,
size_t* out_num_failed);

const CError*
knn_search_index(void* in_index_ptr,
size_t in_dim,
const float* in_query_vector,
size_t in_k,
const char* in_search_parameters,

const int64_t** out_ids,
const float** out_distances,
size_t* out_num_results);

const CError*
dump_index(void* in_index_ptr, const char* in_file_path);

const CError*
load_index(const char* in_file_path,
const char* in_index_type,
const char* in_parameters,

void** out_index_ptr);

void
free_index(void* index_ptr);
void
free_i64_vector(int64_t* vector);
void
free_f32_vector(float* vector);

#ifdef __cplusplus
} // extern "C"
#endif
Loading