fix: refact c struct name (#302)
This commit is contained in:
parent
e2b0903fa5
commit
6ac9bb0177
|
|
@ -20,7 +20,8 @@
|
|||
/**
|
||||
* @brief Print error message and return error code
|
||||
*/
|
||||
static ZVecErrorCode handle_error(ZVecErrorCode error, const char *context) {
|
||||
static zvec_error_code_t handle_error(zvec_error_code_t error,
|
||||
const char *context) {
|
||||
if (error != ZVEC_OK) {
|
||||
char *error_msg = NULL;
|
||||
zvec_get_last_error(&error_msg);
|
||||
|
|
@ -34,19 +35,19 @@ static ZVecErrorCode handle_error(ZVecErrorCode error, const char *context) {
|
|||
/**
|
||||
* @brief Create a simple test collection using CollectionSchema
|
||||
*/
|
||||
static ZVecErrorCode create_simple_test_collection(
|
||||
ZVecCollection **collection) {
|
||||
static zvec_error_code_t create_simple_test_collection(
|
||||
zvec_collection_t **collection) {
|
||||
// Create collection schema using C API
|
||||
ZVecCollectionSchema *schema =
|
||||
zvec_collection_schema_t *schema =
|
||||
zvec_collection_schema_create("test_collection");
|
||||
if (!schema) {
|
||||
return ZVEC_ERROR_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
ZVecErrorCode error = ZVEC_OK;
|
||||
zvec_error_code_t error = ZVEC_OK;
|
||||
|
||||
// Create index parameters using new API
|
||||
ZVecIndexParams *invert_params =
|
||||
zvec_index_params_t *invert_params =
|
||||
zvec_index_params_create(ZVEC_INDEX_TYPE_INVERT);
|
||||
if (!invert_params) {
|
||||
zvec_collection_schema_destroy(schema);
|
||||
|
|
@ -54,7 +55,8 @@ static ZVecErrorCode create_simple_test_collection(
|
|||
}
|
||||
zvec_index_params_set_invert_params(invert_params, true, false);
|
||||
|
||||
ZVecIndexParams *hnsw_params = zvec_index_params_create(ZVEC_INDEX_TYPE_HNSW);
|
||||
zvec_index_params_t *hnsw_params =
|
||||
zvec_index_params_create(ZVEC_INDEX_TYPE_HNSW);
|
||||
if (!hnsw_params) {
|
||||
zvec_index_params_destroy(invert_params);
|
||||
zvec_collection_schema_destroy(schema);
|
||||
|
|
@ -64,7 +66,7 @@ static ZVecErrorCode create_simple_test_collection(
|
|||
zvec_index_params_set_hnsw_params(hnsw_params, 16, 200);
|
||||
|
||||
// Create and add ID field (primary key)
|
||||
ZVecFieldSchema *id_field =
|
||||
zvec_field_schema_t *id_field =
|
||||
zvec_field_schema_create("id", ZVEC_DATA_TYPE_STRING, false, 0);
|
||||
zvec_field_schema_set_index_params(id_field, invert_params);
|
||||
error = zvec_collection_schema_add_field(schema, id_field);
|
||||
|
|
@ -76,7 +78,7 @@ static ZVecErrorCode create_simple_test_collection(
|
|||
}
|
||||
|
||||
// Create text field (inverted index)
|
||||
ZVecFieldSchema *text_field =
|
||||
zvec_field_schema_t *text_field =
|
||||
zvec_field_schema_create("text", ZVEC_DATA_TYPE_STRING, true, 0);
|
||||
zvec_field_schema_set_index_params(text_field, invert_params);
|
||||
error = zvec_collection_schema_add_field(schema, text_field);
|
||||
|
|
@ -88,7 +90,7 @@ static ZVecErrorCode create_simple_test_collection(
|
|||
}
|
||||
|
||||
// Create embedding field (HNSW index)
|
||||
ZVecFieldSchema *embedding_field = zvec_field_schema_create(
|
||||
zvec_field_schema_t *embedding_field = zvec_field_schema_create(
|
||||
"embedding", ZVEC_DATA_TYPE_VECTOR_FP32, false, 3);
|
||||
zvec_field_schema_set_index_params(embedding_field, hnsw_params);
|
||||
error = zvec_collection_schema_add_field(schema, embedding_field);
|
||||
|
|
@ -104,7 +106,7 @@ static ZVecErrorCode create_simple_test_collection(
|
|||
zvec_index_params_destroy(hnsw_params);
|
||||
|
||||
// Use default options
|
||||
ZVecCollectionOptions *options = zvec_collection_options_create();
|
||||
zvec_collection_options_t *options = zvec_collection_options_create();
|
||||
if (!options) {
|
||||
zvec_collection_schema_destroy(schema);
|
||||
return ZVEC_ERROR_RESOURCE_EXHAUSTED;
|
||||
|
|
@ -127,10 +129,10 @@ static ZVecErrorCode create_simple_test_collection(
|
|||
int main() {
|
||||
printf("=== ZVec C API Basic Example ===\n\n");
|
||||
|
||||
ZVecErrorCode error;
|
||||
zvec_error_code_t error;
|
||||
|
||||
// Create collection using simplified function
|
||||
ZVecCollection *collection = NULL;
|
||||
zvec_collection_t *collection = NULL;
|
||||
error = create_simple_test_collection(&collection);
|
||||
if (handle_error(error, "creating collection") != ZVEC_OK) {
|
||||
return 1;
|
||||
|
|
@ -141,7 +143,7 @@ int main() {
|
|||
float vector1[] = {0.1f, 0.2f, 0.3f};
|
||||
float vector2[] = {0.4f, 0.5f, 0.6f};
|
||||
|
||||
ZVecDoc *docs[2];
|
||||
zvec_doc_t *docs[2];
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
docs[i] = zvec_doc_create();
|
||||
if (!docs[i]) {
|
||||
|
|
@ -175,7 +177,7 @@ int main() {
|
|||
// Insert documents
|
||||
size_t success_count = 0;
|
||||
size_t error_count = 0;
|
||||
error = zvec_collection_insert(collection, (const ZVecDoc **)docs, 2,
|
||||
error = zvec_collection_insert(collection, (const zvec_doc_t **)docs, 2,
|
||||
&success_count, &error_count);
|
||||
if (handle_error(error, "inserting documents") != ZVEC_OK) {
|
||||
zvec_collection_destroy(collection);
|
||||
|
|
@ -196,7 +198,7 @@ int main() {
|
|||
}
|
||||
|
||||
// Get collection statistics
|
||||
ZVecCollectionStats *stats = NULL;
|
||||
zvec_collection_stats_t *stats = NULL;
|
||||
error = zvec_collection_get_stats(collection, &stats);
|
||||
if (handle_error(error, "getting collection stats") == ZVEC_OK) {
|
||||
printf("✓ Collection stats - Document count: %llu\n",
|
||||
|
|
@ -207,7 +209,7 @@ int main() {
|
|||
|
||||
printf("Testing vector query...\n");
|
||||
// Query documents
|
||||
ZVecVectorQuery *query = zvec_vector_query_create();
|
||||
zvec_vector_query_t *query = zvec_vector_query_create();
|
||||
if (!query) {
|
||||
fprintf(stderr, "Failed to create vector query\n");
|
||||
zvec_collection_destroy(collection);
|
||||
|
|
@ -221,9 +223,9 @@ int main() {
|
|||
zvec_vector_query_set_include_vector(query, true);
|
||||
zvec_vector_query_set_include_doc_id(query, true);
|
||||
|
||||
ZVecDoc **results = NULL;
|
||||
zvec_doc_t **results = NULL;
|
||||
size_t result_count = 0;
|
||||
error = zvec_collection_query(collection, (const ZVecVectorQuery *)query,
|
||||
error = zvec_collection_query(collection, (const zvec_vector_query_t *)query,
|
||||
&results, &result_count);
|
||||
|
||||
if (error != ZVEC_OK) {
|
||||
|
|
@ -242,7 +244,7 @@ int main() {
|
|||
|
||||
// Process query results
|
||||
for (size_t i = 0; i < result_count && i < 5; ++i) {
|
||||
const ZVecDoc *doc = results[i];
|
||||
const zvec_doc_t *doc = results[i];
|
||||
const char *pk = zvec_doc_get_pk_copy(doc);
|
||||
|
||||
printf(" Result %zu: PK=%s, DocID=%llu, Score=%.4f\n", i + 1,
|
||||
|
|
|
|||
|
|
@ -20,7 +20,8 @@
|
|||
/**
|
||||
* @brief Print error message and return error code
|
||||
*/
|
||||
static ZVecErrorCode handle_error(ZVecErrorCode error, const char *context) {
|
||||
static zvec_error_code_t handle_error(zvec_error_code_t error,
|
||||
const char *context) {
|
||||
if (error != ZVEC_OK) {
|
||||
char *error_msg = NULL;
|
||||
zvec_get_last_error(&error_msg);
|
||||
|
|
@ -37,10 +38,10 @@ static ZVecErrorCode handle_error(ZVecErrorCode error, const char *context) {
|
|||
int main() {
|
||||
printf("=== ZVec Collection Schema Example ===\n\n");
|
||||
|
||||
ZVecErrorCode error;
|
||||
zvec_error_code_t error;
|
||||
|
||||
// 1. Create collection schema
|
||||
ZVecCollectionSchema *schema =
|
||||
zvec_collection_schema_t *schema =
|
||||
zvec_collection_schema_create("schema_example_collection");
|
||||
if (!schema) {
|
||||
fprintf(stderr, "Failed to create collection schema\n");
|
||||
|
|
@ -55,7 +56,7 @@ int main() {
|
|||
zvec_collection_schema_get_max_doc_count_per_segment(schema));
|
||||
|
||||
// 3. Create index parameters
|
||||
ZVecIndexParams *invert_params =
|
||||
zvec_index_params_t *invert_params =
|
||||
zvec_index_params_create(ZVEC_INDEX_TYPE_INVERT);
|
||||
if (!invert_params) {
|
||||
fprintf(stderr, "Failed to create invert index parameters\n");
|
||||
|
|
@ -64,7 +65,8 @@ int main() {
|
|||
}
|
||||
zvec_index_params_set_invert_params(invert_params, true, false);
|
||||
|
||||
ZVecIndexParams *hnsw_params = zvec_index_params_create(ZVEC_INDEX_TYPE_HNSW);
|
||||
zvec_index_params_t *hnsw_params =
|
||||
zvec_index_params_create(ZVEC_INDEX_TYPE_HNSW);
|
||||
if (!hnsw_params) {
|
||||
fprintf(stderr, "Failed to create HNSW index parameters\n");
|
||||
zvec_index_params_destroy(invert_params);
|
||||
|
|
@ -75,7 +77,7 @@ int main() {
|
|||
zvec_index_params_set_hnsw_params(hnsw_params, 16, 200);
|
||||
|
||||
// 4. Create and add ID field (primary key)
|
||||
ZVecFieldSchema *id_field =
|
||||
zvec_field_schema_t *id_field =
|
||||
zvec_field_schema_create("id", ZVEC_DATA_TYPE_STRING, false, 0);
|
||||
if (!id_field) {
|
||||
fprintf(stderr, "Failed to create ID field\n");
|
||||
|
|
@ -91,7 +93,7 @@ int main() {
|
|||
printf("✓ ID field added successfully\n");
|
||||
|
||||
// 5. Create and add text field with inverted index
|
||||
ZVecFieldSchema *text_field =
|
||||
zvec_field_schema_t *text_field =
|
||||
zvec_field_schema_create("content", ZVEC_DATA_TYPE_STRING, true, 0);
|
||||
if (!text_field) {
|
||||
fprintf(stderr, "Failed to create text field\n");
|
||||
|
|
@ -108,7 +110,7 @@ int main() {
|
|||
printf("✓ Text field with inverted index added successfully\n");
|
||||
|
||||
// 6. Create and add vector field with HNSW index
|
||||
ZVecFieldSchema *vector_field = zvec_field_schema_create(
|
||||
zvec_field_schema_t *vector_field = zvec_field_schema_create(
|
||||
"embedding", ZVEC_DATA_TYPE_VECTOR_FP32, false, 128);
|
||||
if (!vector_field) {
|
||||
fprintf(stderr, "Failed to create vector field\n");
|
||||
|
|
@ -130,13 +132,13 @@ int main() {
|
|||
// printf("✓ Total field count: %zu\n", field_count);
|
||||
|
||||
// 8. Create collection with schema
|
||||
ZVecCollectionOptions *options = zvec_collection_options_create();
|
||||
zvec_collection_options_t *options = zvec_collection_options_create();
|
||||
if (!options) {
|
||||
fprintf(stderr, "Failed to create collection options\n");
|
||||
zvec_collection_schema_destroy(schema);
|
||||
return 1;
|
||||
}
|
||||
ZVecCollection *collection = NULL;
|
||||
zvec_collection_t *collection = NULL;
|
||||
|
||||
error = zvec_collection_create_and_open("./schema_example_collection", schema,
|
||||
options, &collection);
|
||||
|
|
@ -157,7 +159,7 @@ int main() {
|
|||
}
|
||||
|
||||
// 10. Create documents
|
||||
ZVecDoc *docs[2];
|
||||
zvec_doc_t *docs[2];
|
||||
for (int i = 0; i < 2; i++) {
|
||||
docs[i] = zvec_doc_create();
|
||||
if (!docs[i]) {
|
||||
|
|
@ -194,7 +196,7 @@ int main() {
|
|||
|
||||
// 11. Insert documents
|
||||
size_t success_count = 0, error_count = 0;
|
||||
error = zvec_collection_insert(collection, (const ZVecDoc **)docs, 2,
|
||||
error = zvec_collection_insert(collection, (const zvec_doc_t **)docs, 2,
|
||||
&success_count, &error_count);
|
||||
if (handle_error(error, "inserting documents") != ZVEC_OK) {
|
||||
// Cleanup
|
||||
|
|
@ -220,7 +222,7 @@ int main() {
|
|||
}
|
||||
|
||||
// 13. Query test
|
||||
ZVecVectorQuery *query = zvec_vector_query_create();
|
||||
zvec_vector_query_t *query = zvec_vector_query_create();
|
||||
if (!query) {
|
||||
fprintf(stderr, "Failed to create vector query\n");
|
||||
zvec_collection_destroy(collection);
|
||||
|
|
@ -234,9 +236,9 @@ int main() {
|
|||
zvec_vector_query_set_include_vector(query, true);
|
||||
zvec_vector_query_set_include_doc_id(query, true);
|
||||
|
||||
ZVecDoc **results = NULL;
|
||||
zvec_doc_t **results = NULL;
|
||||
size_t result_count = 0;
|
||||
error = zvec_collection_query(collection, (const ZVecVectorQuery *)query,
|
||||
error = zvec_collection_query(collection, (const zvec_vector_query_t *)query,
|
||||
&results, &result_count);
|
||||
if (error == ZVEC_OK) {
|
||||
printf("✓ Vector query successful - Returned %zu results\n", result_count);
|
||||
|
|
|
|||
|
|
@ -22,7 +22,8 @@
|
|||
/**
|
||||
* @brief Print error message and return error code
|
||||
*/
|
||||
static ZVecErrorCode handle_error(ZVecErrorCode error, const char *context) {
|
||||
static zvec_error_code_t handle_error(zvec_error_code_t error,
|
||||
const char *context) {
|
||||
if (error != ZVEC_OK) {
|
||||
char *error_msg = NULL;
|
||||
zvec_get_last_error(&error_msg);
|
||||
|
|
@ -36,10 +37,10 @@ static ZVecErrorCode handle_error(ZVecErrorCode error, const char *context) {
|
|||
/**
|
||||
* @brief Create a test document with all data types
|
||||
* @param doc_index Document index for generating unique data
|
||||
* @return ZVecDoc* Created document pointer
|
||||
* @return zvec_doc_t* Created document pointer
|
||||
*/
|
||||
static ZVecDoc *create_full_type_test_doc(int doc_index) {
|
||||
ZVecDoc *doc = zvec_doc_create();
|
||||
static zvec_doc_t *create_full_type_test_doc(int doc_index) {
|
||||
zvec_doc_t *doc = zvec_doc_create();
|
||||
if (!doc) {
|
||||
fprintf(stderr, "Failed to create document\n");
|
||||
return NULL;
|
||||
|
|
@ -107,7 +108,7 @@ static ZVecDoc *create_full_type_test_doc(int doc_index) {
|
|||
/**
|
||||
* @brief Compare two documents for equality
|
||||
*/
|
||||
static bool compare_documents(const ZVecDoc *doc1, const ZVecDoc *doc2) {
|
||||
static bool compare_documents(const zvec_doc_t *doc1, const zvec_doc_t *doc2) {
|
||||
if (!doc1 || !doc2) return false;
|
||||
|
||||
// Compare primary keys
|
||||
|
|
@ -128,7 +129,7 @@ static bool compare_documents(const ZVecDoc *doc1, const ZVecDoc *doc2) {
|
|||
* @param doc The document to print
|
||||
* @param doc_index Document index for identification
|
||||
*/
|
||||
static void print_doc(const ZVecDoc *doc, int doc_index) {
|
||||
static void print_doc(const zvec_doc_t *doc, int doc_index) {
|
||||
if (!doc) {
|
||||
printf("Document %d: NULL document\n", doc_index);
|
||||
return;
|
||||
|
|
@ -154,7 +155,7 @@ static void print_doc(const ZVecDoc *doc, int doc_index) {
|
|||
// ID field (using pointer function for strings)
|
||||
const void *id_value = NULL;
|
||||
size_t id_size = 0;
|
||||
ZVecErrorCode error = zvec_doc_get_field_value_pointer(
|
||||
zvec_error_code_t error = zvec_doc_get_field_value_pointer(
|
||||
doc, "id", ZVEC_DATA_TYPE_STRING, &id_value, &id_size);
|
||||
if (error == ZVEC_OK && id_value) {
|
||||
printf(" id: %.*s\n", (int)id_size, (const char *)id_value);
|
||||
|
|
@ -263,10 +264,10 @@ static void print_doc(const ZVecDoc *doc, int doc_index) {
|
|||
int main() {
|
||||
printf("=== ZVec Document Example ===\n\n");
|
||||
|
||||
ZVecErrorCode error;
|
||||
zvec_error_code_t error;
|
||||
|
||||
// 1. Create collection schema for document testing
|
||||
ZVecCollectionSchema *schema =
|
||||
zvec_collection_schema_t *schema =
|
||||
zvec_collection_schema_create("doc_example_collection");
|
||||
if (!schema) {
|
||||
fprintf(stderr, "Failed to create collection schema\n");
|
||||
|
|
@ -275,7 +276,7 @@ int main() {
|
|||
printf("✓ Collection schema created\n");
|
||||
|
||||
// 2. Create index parameters
|
||||
ZVecIndexParams *invert_params =
|
||||
zvec_index_params_t *invert_params =
|
||||
zvec_index_params_create(ZVEC_INDEX_TYPE_INVERT);
|
||||
if (!invert_params) {
|
||||
fprintf(stderr, "Failed to create invert index parameters\n");
|
||||
|
|
@ -284,7 +285,8 @@ int main() {
|
|||
}
|
||||
zvec_index_params_set_invert_params(invert_params, true, false);
|
||||
|
||||
ZVecIndexParams *hnsw_params = zvec_index_params_create(ZVEC_INDEX_TYPE_HNSW);
|
||||
zvec_index_params_t *hnsw_params =
|
||||
zvec_index_params_create(ZVEC_INDEX_TYPE_HNSW);
|
||||
if (!hnsw_params) {
|
||||
fprintf(stderr, "Failed to create HNSW index parameters\n");
|
||||
zvec_index_params_destroy(invert_params);
|
||||
|
|
@ -298,7 +300,7 @@ int main() {
|
|||
printf("Creating fields for all data types...\n");
|
||||
|
||||
// Id field with inverted index
|
||||
ZVecFieldSchema *id_field =
|
||||
zvec_field_schema_t *id_field =
|
||||
zvec_field_schema_create("id", ZVEC_DATA_TYPE_STRING, false, 0);
|
||||
if (id_field) {
|
||||
zvec_field_schema_set_index_params(id_field, invert_params);
|
||||
|
|
@ -309,17 +311,17 @@ int main() {
|
|||
}
|
||||
|
||||
// Scalar fields
|
||||
ZVecFieldSchema *string_field =
|
||||
zvec_field_schema_t *string_field =
|
||||
zvec_field_schema_create("string_field", ZVEC_DATA_TYPE_STRING, true, 0);
|
||||
ZVecFieldSchema *bool_field =
|
||||
zvec_field_schema_t *bool_field =
|
||||
zvec_field_schema_create("bool_field", ZVEC_DATA_TYPE_BOOL, true, 0);
|
||||
ZVecFieldSchema *int32_field =
|
||||
zvec_field_schema_t *int32_field =
|
||||
zvec_field_schema_create("int32_field", ZVEC_DATA_TYPE_INT32, true, 0);
|
||||
ZVecFieldSchema *int64_field =
|
||||
zvec_field_schema_t *int64_field =
|
||||
zvec_field_schema_create("int64_field", ZVEC_DATA_TYPE_INT64, true, 0);
|
||||
ZVecFieldSchema *float_field =
|
||||
zvec_field_schema_t *float_field =
|
||||
zvec_field_schema_create("float_field", ZVEC_DATA_TYPE_FLOAT, true, 0);
|
||||
ZVecFieldSchema *double_field =
|
||||
zvec_field_schema_t *double_field =
|
||||
zvec_field_schema_create("double_field", ZVEC_DATA_TYPE_DOUBLE, true, 0);
|
||||
|
||||
if (string_field) zvec_collection_schema_add_field(schema, string_field);
|
||||
|
|
@ -330,9 +332,9 @@ int main() {
|
|||
if (double_field) zvec_collection_schema_add_field(schema, double_field);
|
||||
|
||||
// Vector fields
|
||||
ZVecFieldSchema *vector_fp32_field = zvec_field_schema_create(
|
||||
zvec_field_schema_t *vector_fp32_field = zvec_field_schema_create(
|
||||
"vector_fp32", ZVEC_DATA_TYPE_VECTOR_FP32, false, 3);
|
||||
ZVecFieldSchema *large_vector_field = zvec_field_schema_create(
|
||||
zvec_field_schema_t *large_vector_field = zvec_field_schema_create(
|
||||
"large_vector", ZVEC_DATA_TYPE_VECTOR_FP32, false, 16);
|
||||
|
||||
if (vector_fp32_field) {
|
||||
|
|
@ -352,13 +354,13 @@ int main() {
|
|||
}
|
||||
|
||||
// 4. Create collection
|
||||
ZVecCollectionOptions *options = zvec_collection_options_create();
|
||||
zvec_collection_options_t *options = zvec_collection_options_create();
|
||||
if (!options) {
|
||||
fprintf(stderr, "Failed to create collection options\n");
|
||||
zvec_collection_schema_destroy(schema);
|
||||
return -1;
|
||||
}
|
||||
ZVecCollection *collection = NULL;
|
||||
zvec_collection_t *collection = NULL;
|
||||
|
||||
error = zvec_collection_create_and_open("./doc_example_collection", schema,
|
||||
options, &collection);
|
||||
|
|
@ -374,7 +376,8 @@ int main() {
|
|||
|
||||
#define DOC_COUNT 5
|
||||
// Use dynamic allocation for MSVC compatibility (no VLA support)
|
||||
ZVecDoc **test_docs = (ZVecDoc **)malloc(DOC_COUNT * sizeof(ZVecDoc *));
|
||||
zvec_doc_t **test_docs =
|
||||
(zvec_doc_t **)malloc(DOC_COUNT * sizeof(zvec_doc_t *));
|
||||
if (!test_docs) {
|
||||
fprintf(stderr, "Failed to allocate test documents\n");
|
||||
goto cleanup;
|
||||
|
|
@ -402,7 +405,7 @@ int main() {
|
|||
|
||||
// Insert documents
|
||||
size_t success_count = 0, error_count = 0;
|
||||
error = zvec_collection_insert(collection, (const ZVecDoc **)test_docs,
|
||||
error = zvec_collection_insert(collection, (const zvec_doc_t **)test_docs,
|
||||
DOC_COUNT, &success_count, &error_count);
|
||||
if (handle_error(error, "inserting documents") == ZVEC_OK) {
|
||||
printf("✓ Documents inserted - Success: %zu, Failed: %zu\n", success_count,
|
||||
|
|
@ -419,7 +422,7 @@ int main() {
|
|||
|
||||
// Use the first document's vector for querying
|
||||
float query_vector[] = {0.0f, 0.0f, 0.0f};
|
||||
ZVecVectorQuery *query = zvec_vector_query_create();
|
||||
zvec_vector_query_t *query = zvec_vector_query_create();
|
||||
if (!query) {
|
||||
fprintf(stderr, "Failed to create vector query\n");
|
||||
zvec_collection_destroy(collection);
|
||||
|
|
@ -433,10 +436,10 @@ int main() {
|
|||
zvec_vector_query_set_include_vector(query, true);
|
||||
zvec_vector_query_set_include_doc_id(query, true);
|
||||
|
||||
ZVecDoc **query_results = NULL;
|
||||
zvec_doc_t **query_results = NULL;
|
||||
size_t result_count = 0;
|
||||
|
||||
error = zvec_collection_query(collection, (const ZVecVectorQuery *)query,
|
||||
error = zvec_collection_query(collection, (const zvec_vector_query_t *)query,
|
||||
&query_results, &result_count);
|
||||
if (handle_error(error, "querying documents") != ZVEC_OK) {
|
||||
query_results = NULL;
|
||||
|
|
@ -483,10 +486,10 @@ int main() {
|
|||
// Create filtered query
|
||||
zvec_vector_query_set_filter(query, "string_field = 'string_field_0'");
|
||||
|
||||
ZVecDoc **filtered_results = NULL;
|
||||
zvec_doc_t **filtered_results = NULL;
|
||||
size_t filtered_count = 0;
|
||||
|
||||
error = zvec_collection_query(collection, (const ZVecVectorQuery *)query,
|
||||
error = zvec_collection_query(collection, (const zvec_vector_query_t *)query,
|
||||
&filtered_results, &filtered_count);
|
||||
if (handle_error(error, "filtered querying") == ZVEC_OK) {
|
||||
printf("Filtered query returned %zu results\n", filtered_count);
|
||||
|
|
|
|||
|
|
@ -20,7 +20,8 @@
|
|||
/**
|
||||
* @brief Print error message and return error code
|
||||
*/
|
||||
static ZVecErrorCode handle_error(ZVecErrorCode error, const char *context) {
|
||||
static zvec_error_code_t handle_error(zvec_error_code_t error,
|
||||
const char *context) {
|
||||
if (error != ZVEC_OK) {
|
||||
char *error_msg = NULL;
|
||||
zvec_get_last_error(&error_msg);
|
||||
|
|
@ -37,10 +38,10 @@ static ZVecErrorCode handle_error(ZVecErrorCode error, const char *context) {
|
|||
int main() {
|
||||
printf("=== ZVec Field Schema Example ===\n\n");
|
||||
|
||||
ZVecErrorCode error;
|
||||
zvec_error_code_t error;
|
||||
|
||||
// 1. Create collection schema
|
||||
ZVecCollectionSchema *schema =
|
||||
zvec_collection_schema_t *schema =
|
||||
zvec_collection_schema_create("field_example_collection");
|
||||
if (!schema) {
|
||||
fprintf(stderr, "Failed to create collection schema\n");
|
||||
|
|
@ -49,7 +50,7 @@ int main() {
|
|||
printf("✓ Collection schema created successfully\n");
|
||||
|
||||
// 2. Create different types of index parameters
|
||||
ZVecIndexParams *invert_params =
|
||||
zvec_index_params_t *invert_params =
|
||||
zvec_index_params_create(ZVEC_INDEX_TYPE_INVERT);
|
||||
if (!invert_params) {
|
||||
fprintf(stderr, "Failed to create invert index parameters\n");
|
||||
|
|
@ -58,7 +59,8 @@ int main() {
|
|||
}
|
||||
zvec_index_params_set_invert_params(invert_params, true, false);
|
||||
|
||||
ZVecIndexParams *hnsw_params = zvec_index_params_create(ZVEC_INDEX_TYPE_HNSW);
|
||||
zvec_index_params_t *hnsw_params =
|
||||
zvec_index_params_create(ZVEC_INDEX_TYPE_HNSW);
|
||||
if (!hnsw_params) {
|
||||
fprintf(stderr, "Failed to create HNSW index parameters\n");
|
||||
zvec_index_params_destroy(invert_params);
|
||||
|
|
@ -68,7 +70,8 @@ int main() {
|
|||
zvec_index_params_set_metric_type(hnsw_params, ZVEC_METRIC_TYPE_COSINE);
|
||||
zvec_index_params_set_hnsw_params(hnsw_params, 16, 200);
|
||||
|
||||
ZVecIndexParams *flat_params = zvec_index_params_create(ZVEC_INDEX_TYPE_FLAT);
|
||||
zvec_index_params_t *flat_params =
|
||||
zvec_index_params_create(ZVEC_INDEX_TYPE_FLAT);
|
||||
if (!flat_params) {
|
||||
fprintf(stderr, "Failed to create Flat index parameters\n");
|
||||
zvec_index_params_destroy(invert_params);
|
||||
|
|
@ -91,7 +94,7 @@ int main() {
|
|||
printf("Creating scalar fields...\n");
|
||||
|
||||
// String field with inverted index
|
||||
ZVecFieldSchema *name_field =
|
||||
zvec_field_schema_t *name_field =
|
||||
zvec_field_schema_create("name", ZVEC_DATA_TYPE_STRING, false, 0);
|
||||
if (name_field) {
|
||||
zvec_field_schema_set_index_params(name_field, invert_params);
|
||||
|
|
@ -102,7 +105,7 @@ int main() {
|
|||
}
|
||||
|
||||
// Integer field
|
||||
ZVecFieldSchema *age_field =
|
||||
zvec_field_schema_t *age_field =
|
||||
zvec_field_schema_create("age", ZVEC_DATA_TYPE_INT32, true, 0);
|
||||
if (age_field) {
|
||||
error = zvec_collection_schema_add_field(schema, age_field);
|
||||
|
|
@ -112,7 +115,7 @@ int main() {
|
|||
}
|
||||
|
||||
// Float field
|
||||
ZVecFieldSchema *score_field =
|
||||
zvec_field_schema_t *score_field =
|
||||
zvec_field_schema_create("score", ZVEC_DATA_TYPE_FLOAT, true, 0);
|
||||
if (score_field) {
|
||||
error = zvec_collection_schema_add_field(schema, score_field);
|
||||
|
|
@ -122,7 +125,7 @@ int main() {
|
|||
}
|
||||
|
||||
// Boolean field
|
||||
ZVecFieldSchema *active_field =
|
||||
zvec_field_schema_t *active_field =
|
||||
zvec_field_schema_create("active", ZVEC_DATA_TYPE_BOOL, false, 0);
|
||||
if (active_field) {
|
||||
error = zvec_collection_schema_add_field(schema, active_field);
|
||||
|
|
@ -135,7 +138,7 @@ int main() {
|
|||
printf("Creating vector fields...\n");
|
||||
|
||||
// Small dimension vector with HNSW index
|
||||
ZVecFieldSchema *small_vector_field = zvec_field_schema_create(
|
||||
zvec_field_schema_t *small_vector_field = zvec_field_schema_create(
|
||||
"small_vector", ZVEC_DATA_TYPE_VECTOR_FP32, false, 32);
|
||||
if (small_vector_field) {
|
||||
zvec_field_schema_set_index_params(small_vector_field, hnsw_params);
|
||||
|
|
@ -147,7 +150,7 @@ int main() {
|
|||
}
|
||||
|
||||
// Medium dimension vector with Flat index
|
||||
ZVecFieldSchema *medium_vector_field = zvec_field_schema_create(
|
||||
zvec_field_schema_t *medium_vector_field = zvec_field_schema_create(
|
||||
"medium_vector", ZVEC_DATA_TYPE_VECTOR_FP32, false, 128);
|
||||
if (medium_vector_field) {
|
||||
zvec_field_schema_set_index_params(medium_vector_field, flat_params);
|
||||
|
|
@ -160,7 +163,7 @@ int main() {
|
|||
}
|
||||
|
||||
// Large dimension vector with HNSW index
|
||||
ZVecFieldSchema *large_vector_field = zvec_field_schema_create(
|
||||
zvec_field_schema_t *large_vector_field = zvec_field_schema_create(
|
||||
"large_vector", ZVEC_DATA_TYPE_VECTOR_FP32, false, 512);
|
||||
if (large_vector_field) {
|
||||
zvec_field_schema_set_index_params(large_vector_field, hnsw_params);
|
||||
|
|
@ -172,13 +175,13 @@ int main() {
|
|||
}
|
||||
|
||||
// 5. Create collection with the schema
|
||||
ZVecCollectionOptions *options = zvec_collection_options_create();
|
||||
zvec_collection_options_t *options = zvec_collection_options_create();
|
||||
if (!options) {
|
||||
fprintf(stderr, "Failed to create collection options\n");
|
||||
zvec_collection_schema_destroy(schema);
|
||||
return -1;
|
||||
}
|
||||
ZVecCollection *collection = NULL;
|
||||
zvec_collection_t *collection = NULL;
|
||||
|
||||
error = zvec_collection_create_and_open("./field_example_collection", schema,
|
||||
options, &collection);
|
||||
|
|
@ -192,8 +195,8 @@ int main() {
|
|||
// 6. Create test documents with various field types
|
||||
printf("Creating test documents...\n");
|
||||
|
||||
ZVecDoc *doc1 = zvec_doc_create();
|
||||
ZVecDoc *doc2 = zvec_doc_create();
|
||||
zvec_doc_t *doc1 = zvec_doc_create();
|
||||
zvec_doc_t *doc2 = zvec_doc_create();
|
||||
|
||||
if (!doc1 || !doc2) {
|
||||
fprintf(stderr, "Failed to create documents\n");
|
||||
|
|
@ -261,9 +264,9 @@ int main() {
|
|||
large_vec2, 512 * sizeof(float));
|
||||
|
||||
// 7. Insert documents
|
||||
ZVecDoc *docs[] = {doc1, doc2};
|
||||
zvec_doc_t *docs[] = {doc1, doc2};
|
||||
size_t success_count = 0, error_count = 0;
|
||||
error = zvec_collection_insert(collection, (const ZVecDoc **)docs, 2,
|
||||
error = zvec_collection_insert(collection, (const zvec_doc_t **)docs, 2,
|
||||
&success_count, &error_count);
|
||||
if (handle_error(error, "inserting documents") == ZVEC_OK) {
|
||||
printf("✓ Documents inserted - Success: %zu, Failed: %zu\n", success_count,
|
||||
|
|
@ -275,7 +278,7 @@ int main() {
|
|||
printf("✓ Collection flushed\n");
|
||||
|
||||
// Test vector query on medium vector field
|
||||
ZVecVectorQuery *query = zvec_vector_query_create();
|
||||
zvec_vector_query_t *query = zvec_vector_query_create();
|
||||
if (!query) {
|
||||
fprintf(stderr, "Failed to create vector query\n");
|
||||
goto cleanup;
|
||||
|
|
@ -287,9 +290,9 @@ int main() {
|
|||
zvec_vector_query_set_include_vector(query, false);
|
||||
zvec_vector_query_set_include_doc_id(query, true);
|
||||
|
||||
ZVecDoc **results = NULL;
|
||||
zvec_doc_t **results = NULL;
|
||||
size_t result_count = 0;
|
||||
error = zvec_collection_query(collection, (const ZVecVectorQuery *)query,
|
||||
error = zvec_collection_query(collection, (const zvec_vector_query_t *)query,
|
||||
&results, &result_count);
|
||||
if (error == ZVEC_OK) {
|
||||
printf("✓ Vector query successful - Found %zu results\n", result_count);
|
||||
|
|
|
|||
|
|
@ -20,7 +20,8 @@
|
|||
/**
|
||||
* @brief Print error message and return error code
|
||||
*/
|
||||
static ZVecErrorCode handle_error(ZVecErrorCode error, const char *context) {
|
||||
static zvec_error_code_t handle_error(zvec_error_code_t error,
|
||||
const char *context) {
|
||||
if (error != ZVEC_OK) {
|
||||
char *error_msg = NULL;
|
||||
zvec_get_last_error(&error_msg);
|
||||
|
|
@ -37,10 +38,10 @@ static ZVecErrorCode handle_error(ZVecErrorCode error, const char *context) {
|
|||
int main() {
|
||||
printf("=== ZVec Index Example ===\n\n");
|
||||
|
||||
ZVecErrorCode error;
|
||||
zvec_error_code_t error;
|
||||
|
||||
// 1. Create collection schema
|
||||
ZVecCollectionSchema *schema =
|
||||
zvec_collection_schema_t *schema =
|
||||
zvec_collection_schema_create("index_example_collection");
|
||||
if (!schema) {
|
||||
fprintf(stderr, "Failed to create collection schema\n");
|
||||
|
|
@ -52,7 +53,7 @@ int main() {
|
|||
printf("Creating index parameters...\n");
|
||||
|
||||
// Inverted index parameters
|
||||
ZVecIndexParams *invert_params_standard =
|
||||
zvec_index_params_t *invert_params_standard =
|
||||
zvec_index_params_create(ZVEC_INDEX_TYPE_INVERT);
|
||||
if (!invert_params_standard) {
|
||||
fprintf(stderr, "Failed to create invert index parameters (standard)\n");
|
||||
|
|
@ -61,7 +62,7 @@ int main() {
|
|||
}
|
||||
zvec_index_params_set_invert_params(invert_params_standard, true, false);
|
||||
|
||||
ZVecIndexParams *invert_params_extended =
|
||||
zvec_index_params_t *invert_params_extended =
|
||||
zvec_index_params_create(ZVEC_INDEX_TYPE_INVERT);
|
||||
if (!invert_params_extended) {
|
||||
fprintf(stderr, "Failed to create invert index parameters (extended)\n");
|
||||
|
|
@ -72,7 +73,7 @@ int main() {
|
|||
zvec_index_params_set_invert_params(invert_params_extended, true, true);
|
||||
|
||||
// HNSW index parameters with different configurations
|
||||
ZVecIndexParams *hnsw_params_fast =
|
||||
zvec_index_params_t *hnsw_params_fast =
|
||||
zvec_index_params_create(ZVEC_INDEX_TYPE_HNSW);
|
||||
if (!hnsw_params_fast) {
|
||||
fprintf(stderr, "Failed to create HNSW index parameters (fast)\n");
|
||||
|
|
@ -84,7 +85,7 @@ int main() {
|
|||
zvec_index_params_set_metric_type(hnsw_params_fast, ZVEC_METRIC_TYPE_L2);
|
||||
zvec_index_params_set_hnsw_params(hnsw_params_fast, 16, 100);
|
||||
|
||||
ZVecIndexParams *hnsw_params_balanced =
|
||||
zvec_index_params_t *hnsw_params_balanced =
|
||||
zvec_index_params_create(ZVEC_INDEX_TYPE_HNSW);
|
||||
if (!hnsw_params_balanced) {
|
||||
fprintf(stderr, "Failed to create HNSW index parameters (balanced)\n");
|
||||
|
|
@ -98,7 +99,7 @@ int main() {
|
|||
ZVEC_METRIC_TYPE_COSINE);
|
||||
zvec_index_params_set_hnsw_params(hnsw_params_balanced, 32, 200);
|
||||
|
||||
ZVecIndexParams *hnsw_params_accurate =
|
||||
zvec_index_params_t *hnsw_params_accurate =
|
||||
zvec_index_params_create(ZVEC_INDEX_TYPE_HNSW);
|
||||
if (!hnsw_params_accurate) {
|
||||
fprintf(stderr, "Failed to create HNSW index parameters (accurate)\n");
|
||||
|
|
@ -113,7 +114,7 @@ int main() {
|
|||
zvec_index_params_set_hnsw_params(hnsw_params_accurate, 64, 400);
|
||||
|
||||
// Flat index parameters
|
||||
ZVecIndexParams *flat_params_l2 =
|
||||
zvec_index_params_t *flat_params_l2 =
|
||||
zvec_index_params_create(ZVEC_INDEX_TYPE_FLAT);
|
||||
if (!flat_params_l2) {
|
||||
fprintf(stderr, "Failed to create Flat index parameters (L2)\n");
|
||||
|
|
@ -127,7 +128,7 @@ int main() {
|
|||
}
|
||||
zvec_index_params_set_metric_type(flat_params_l2, ZVEC_METRIC_TYPE_L2);
|
||||
|
||||
ZVecIndexParams *flat_params_cosine =
|
||||
zvec_index_params_t *flat_params_cosine =
|
||||
zvec_index_params_create(ZVEC_INDEX_TYPE_FLAT);
|
||||
if (!flat_params_cosine) {
|
||||
fprintf(stderr, "Failed to create Flat index parameters (cosine)\n");
|
||||
|
|
@ -147,7 +148,7 @@ int main() {
|
|||
printf("Creating fields with various index types...\n");
|
||||
|
||||
// Fields with inverted indexes
|
||||
ZVecFieldSchema *id_field =
|
||||
zvec_field_schema_t *id_field =
|
||||
zvec_field_schema_create("id", ZVEC_DATA_TYPE_STRING, false, 0);
|
||||
if (id_field) {
|
||||
zvec_field_schema_set_index_params(id_field, invert_params_standard);
|
||||
|
|
@ -157,7 +158,7 @@ int main() {
|
|||
}
|
||||
}
|
||||
|
||||
ZVecFieldSchema *category_field =
|
||||
zvec_field_schema_t *category_field =
|
||||
zvec_field_schema_create("category", ZVEC_DATA_TYPE_STRING, true, 0);
|
||||
if (category_field) {
|
||||
zvec_field_schema_set_index_params(category_field, invert_params_extended);
|
||||
|
|
@ -168,7 +169,7 @@ int main() {
|
|||
}
|
||||
|
||||
// Vector fields with HNSW indexes (different configurations)
|
||||
ZVecFieldSchema *fast_search_field = zvec_field_schema_create(
|
||||
zvec_field_schema_t *fast_search_field = zvec_field_schema_create(
|
||||
"fast_vector", ZVEC_DATA_TYPE_VECTOR_FP32, false, 64);
|
||||
if (fast_search_field) {
|
||||
zvec_field_schema_set_index_params(fast_search_field, hnsw_params_fast);
|
||||
|
|
@ -178,7 +179,7 @@ int main() {
|
|||
}
|
||||
}
|
||||
|
||||
ZVecFieldSchema *balanced_field = zvec_field_schema_create(
|
||||
zvec_field_schema_t *balanced_field = zvec_field_schema_create(
|
||||
"balanced_vector", ZVEC_DATA_TYPE_VECTOR_FP32, false, 128);
|
||||
if (balanced_field) {
|
||||
zvec_field_schema_set_index_params(balanced_field, hnsw_params_balanced);
|
||||
|
|
@ -188,7 +189,7 @@ int main() {
|
|||
}
|
||||
}
|
||||
|
||||
ZVecFieldSchema *accurate_field = zvec_field_schema_create(
|
||||
zvec_field_schema_t *accurate_field = zvec_field_schema_create(
|
||||
"accurate_vector", ZVEC_DATA_TYPE_VECTOR_FP32, false, 256);
|
||||
if (accurate_field) {
|
||||
zvec_field_schema_set_index_params(accurate_field, hnsw_params_accurate);
|
||||
|
|
@ -199,7 +200,7 @@ int main() {
|
|||
}
|
||||
|
||||
// Vector field with Flat index
|
||||
ZVecFieldSchema *exact_field = zvec_field_schema_create(
|
||||
zvec_field_schema_t *exact_field = zvec_field_schema_create(
|
||||
"exact_vector", ZVEC_DATA_TYPE_VECTOR_FP32, false, 32);
|
||||
if (exact_field) {
|
||||
zvec_field_schema_set_index_params(exact_field, flat_params_l2);
|
||||
|
|
@ -210,13 +211,13 @@ int main() {
|
|||
}
|
||||
|
||||
// 4. Create collection
|
||||
ZVecCollectionOptions *options = zvec_collection_options_create();
|
||||
zvec_collection_options_t *options = zvec_collection_options_create();
|
||||
if (!options) {
|
||||
fprintf(stderr, "Failed to create collection options\n");
|
||||
zvec_collection_schema_destroy(schema);
|
||||
return -1;
|
||||
}
|
||||
ZVecCollection *collection = NULL;
|
||||
zvec_collection_t *collection = NULL;
|
||||
|
||||
error = zvec_collection_create_and_open("./index_example_collection", schema,
|
||||
options, &collection);
|
||||
|
|
@ -230,7 +231,7 @@ int main() {
|
|||
// 5. Create test data
|
||||
printf("Creating test documents...\n");
|
||||
|
||||
ZVecDoc *docs[3];
|
||||
zvec_doc_t *docs[3];
|
||||
for (int i = 0; i < 3; i++) {
|
||||
docs[i] = zvec_doc_create();
|
||||
if (!docs[i]) {
|
||||
|
|
@ -297,7 +298,7 @@ int main() {
|
|||
|
||||
// 6. Insert documents
|
||||
size_t success_count = 0, error_count = 0;
|
||||
error = zvec_collection_insert(collection, (const ZVecDoc **)docs, 3,
|
||||
error = zvec_collection_insert(collection, (const zvec_doc_t **)docs, 3,
|
||||
&success_count, &error_count);
|
||||
if (handle_error(error, "inserting documents") == ZVEC_OK) {
|
||||
printf("✓ Documents inserted - Success: %zu, Failed: %zu\n", success_count,
|
||||
|
|
@ -319,7 +320,7 @@ int main() {
|
|||
printf("Testing various index queries...\n");
|
||||
|
||||
// Test HNSW query (balanced)
|
||||
ZVecVectorQuery *hnsw_query = zvec_vector_query_create();
|
||||
zvec_vector_query_t *hnsw_query = zvec_vector_query_create();
|
||||
if (!hnsw_query) {
|
||||
fprintf(stderr, "Failed to create HNSW query\n");
|
||||
goto cleanup;
|
||||
|
|
@ -332,10 +333,11 @@ int main() {
|
|||
zvec_vector_query_set_include_vector(hnsw_query, false);
|
||||
zvec_vector_query_set_include_doc_id(hnsw_query, true);
|
||||
|
||||
ZVecDoc **hnsw_results = NULL;
|
||||
zvec_doc_t **hnsw_results = NULL;
|
||||
size_t hnsw_result_count = 0;
|
||||
error = zvec_collection_query(collection, (const ZVecVectorQuery *)hnsw_query,
|
||||
&hnsw_results, &hnsw_result_count);
|
||||
error =
|
||||
zvec_collection_query(collection, (const zvec_vector_query_t *)hnsw_query,
|
||||
&hnsw_results, &hnsw_result_count);
|
||||
if (error == ZVEC_OK) {
|
||||
printf("✓ HNSW query successful - Found %zu results\n", hnsw_result_count);
|
||||
zvec_docs_free(hnsw_results, hnsw_result_count);
|
||||
|
|
@ -343,7 +345,7 @@ int main() {
|
|||
zvec_vector_query_destroy(hnsw_query);
|
||||
|
||||
// Test Flat query (exact)
|
||||
ZVecVectorQuery *flat_query = zvec_vector_query_create();
|
||||
zvec_vector_query_t *flat_query = zvec_vector_query_create();
|
||||
if (!flat_query) {
|
||||
fprintf(stderr, "Failed to create Flat query\n");
|
||||
goto cleanup;
|
||||
|
|
@ -356,10 +358,11 @@ int main() {
|
|||
zvec_vector_query_set_include_vector(flat_query, false);
|
||||
zvec_vector_query_set_include_doc_id(flat_query, true);
|
||||
|
||||
ZVecDoc **flat_results = NULL;
|
||||
zvec_doc_t **flat_results = NULL;
|
||||
size_t flat_result_count = 0;
|
||||
error = zvec_collection_query(collection, (const ZVecVectorQuery *)flat_query,
|
||||
&flat_results, &flat_result_count);
|
||||
error =
|
||||
zvec_collection_query(collection, (const zvec_vector_query_t *)flat_query,
|
||||
&flat_results, &flat_result_count);
|
||||
if (error == ZVEC_OK) {
|
||||
printf("✓ Flat (exact) query successful - Found %zu results\n",
|
||||
flat_result_count);
|
||||
|
|
|
|||
|
|
@ -21,7 +21,8 @@
|
|||
/**
|
||||
* @brief Print error message and return error code
|
||||
*/
|
||||
static ZVecErrorCode handle_error(ZVecErrorCode error, const char *context) {
|
||||
static zvec_error_code_t handle_error(zvec_error_code_t error,
|
||||
const char *context) {
|
||||
if (error != ZVEC_OK) {
|
||||
char *error_msg = NULL;
|
||||
zvec_get_last_error(&error_msg);
|
||||
|
|
@ -58,10 +59,10 @@ int main() {
|
|||
const char *version = zvec_get_version();
|
||||
printf("ZVec Version: %s\n\n", version ? version : "Unknown");
|
||||
|
||||
ZVecErrorCode error;
|
||||
zvec_error_code_t error;
|
||||
|
||||
// 1. Create optimized collection schema
|
||||
ZVecCollectionSchema *schema =
|
||||
zvec_collection_schema_t *schema =
|
||||
zvec_collection_schema_create("optimized_example_collection");
|
||||
if (!schema) {
|
||||
fprintf(stderr, "Failed to create collection schema\n");
|
||||
|
|
@ -70,7 +71,8 @@ int main() {
|
|||
printf("✓ Collection schema created\n");
|
||||
|
||||
// 2. Create optimized index parameters
|
||||
ZVecIndexParams *hnsw_params = zvec_index_params_create(ZVEC_INDEX_TYPE_HNSW);
|
||||
zvec_index_params_t *hnsw_params =
|
||||
zvec_index_params_create(ZVEC_INDEX_TYPE_HNSW);
|
||||
if (!hnsw_params) {
|
||||
fprintf(stderr, "Failed to create HNSW index parameters\n");
|
||||
zvec_collection_schema_destroy(schema);
|
||||
|
|
@ -80,11 +82,11 @@ int main() {
|
|||
zvec_index_params_set_hnsw_params(hnsw_params, 32, 200);
|
||||
|
||||
// 3. Create fields with optimized configuration
|
||||
ZVecFieldSchema *id_field =
|
||||
zvec_field_schema_t *id_field =
|
||||
zvec_field_schema_create("id", ZVEC_DATA_TYPE_STRING, false, 0);
|
||||
ZVecFieldSchema *text_field =
|
||||
zvec_field_schema_t *text_field =
|
||||
zvec_field_schema_create("text", ZVEC_DATA_TYPE_STRING, true, 0);
|
||||
ZVecFieldSchema *embedding_field = zvec_field_schema_create(
|
||||
zvec_field_schema_t *embedding_field = zvec_field_schema_create(
|
||||
"embedding", ZVEC_DATA_TYPE_VECTOR_FP32, false, 128);
|
||||
|
||||
if (!id_field || !text_field || !embedding_field) {
|
||||
|
|
@ -109,7 +111,7 @@ int main() {
|
|||
printf("✓ Fields configured with indexes\n");
|
||||
|
||||
// 4. Create collection with optimized options
|
||||
ZVecCollectionOptions *options = zvec_collection_options_create();
|
||||
zvec_collection_options_t *options = zvec_collection_options_create();
|
||||
if (!options) {
|
||||
fprintf(stderr, "Failed to create collection options\n");
|
||||
goto cleanup_fields;
|
||||
|
|
@ -117,7 +119,7 @@ int main() {
|
|||
zvec_collection_options_set_enable_mmap(
|
||||
options, true); // Enable memory mapping for better performance
|
||||
|
||||
ZVecCollection *collection = NULL;
|
||||
zvec_collection_t *collection = NULL;
|
||||
error = zvec_collection_create_and_open("./optimized_example_collection",
|
||||
schema, options, &collection);
|
||||
zvec_collection_options_destroy(options);
|
||||
|
|
@ -141,7 +143,7 @@ int main() {
|
|||
? DOC_COUNT - batch_start
|
||||
: BATCH_SIZE;
|
||||
|
||||
ZVecDoc **batch_docs = malloc(current_batch_size * sizeof(ZVecDoc *));
|
||||
zvec_doc_t **batch_docs = malloc(current_batch_size * sizeof(zvec_doc_t *));
|
||||
if (!batch_docs) {
|
||||
fprintf(stderr, "Failed to allocate batch documents\n");
|
||||
break;
|
||||
|
|
@ -190,7 +192,7 @@ int main() {
|
|||
|
||||
// Insert batch
|
||||
size_t success_count, error_count;
|
||||
error = zvec_collection_insert(collection, (const ZVecDoc **)batch_docs,
|
||||
error = zvec_collection_insert(collection, (const zvec_doc_t **)batch_docs,
|
||||
current_batch_size, &success_count,
|
||||
&error_count);
|
||||
if (handle_error(error, "inserting batch") != ZVEC_OK) {
|
||||
|
|
@ -233,7 +235,7 @@ int main() {
|
|||
goto cleanup_collection;
|
||||
}
|
||||
|
||||
ZVecVectorQuery *query = zvec_vector_query_create();
|
||||
zvec_vector_query_t *query = zvec_vector_query_create();
|
||||
if (!query) {
|
||||
fprintf(stderr, "Failed to create vector query\n");
|
||||
free(query_vector);
|
||||
|
|
@ -250,11 +252,12 @@ int main() {
|
|||
start_time = clock();
|
||||
|
||||
for (int q = 0; q < QUERY_COUNT; q++) {
|
||||
ZVecDoc **results = NULL;
|
||||
zvec_doc_t **results = NULL;
|
||||
size_t result_count = 0;
|
||||
|
||||
error = zvec_collection_query(collection, (const ZVecVectorQuery *)query,
|
||||
&results, &result_count);
|
||||
error =
|
||||
zvec_collection_query(collection, (const zvec_vector_query_t *)query,
|
||||
&results, &result_count);
|
||||
if (error != ZVEC_OK) {
|
||||
char *error_msg = NULL;
|
||||
zvec_get_last_error(&error_msg);
|
||||
|
|
@ -281,7 +284,7 @@ int main() {
|
|||
zvec_vector_query_destroy(query);
|
||||
|
||||
// 8. Memory usage information
|
||||
ZVecCollectionStats *stats = NULL;
|
||||
zvec_collection_stats_t *stats = NULL;
|
||||
error = zvec_collection_get_stats(collection, &stats);
|
||||
if (error == ZVEC_OK && stats) {
|
||||
printf("Collection Statistics:\n");
|
||||
|
|
|
|||
|
|
@ -185,12 +185,46 @@ else()
|
|||
${CMAKE_DL_LIBS}
|
||||
)
|
||||
|
||||
# Static link libstdc++ to avoid runtime dependency
|
||||
# Must be done in target_link_options to ensure correct order
|
||||
target_link_options(zvec_c_api PRIVATE
|
||||
-static-libstdc++
|
||||
-static-libgcc
|
||||
# Link C++ standard library appropriately for the platform
|
||||
# On Linux, we need to explicitly link libstdc++
|
||||
# Try static linking first, fall back to dynamic
|
||||
|
||||
set(STATIC_LIBS_FOUND FALSE)
|
||||
|
||||
# Try to find static libraries using compiler's built-in search
|
||||
execute_process(
|
||||
COMMAND ${CMAKE_CXX_COMPILER} -print-file-name=libstdc++.a
|
||||
OUTPUT_VARIABLE LIBSTDCPP_A_PATH
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
execute_process(
|
||||
COMMAND ${CMAKE_CXX_COMPILER} -print-file-name=libgcc.a
|
||||
OUTPUT_VARIABLE LIBGCC_A_PATH
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
)
|
||||
|
||||
# Check if both static libraries exist (not just filename returned)
|
||||
# If library not found, -print-file-name returns just the filename without path
|
||||
if(EXISTS "${LIBSTDCPP_A_PATH}" AND EXISTS "${LIBGCC_A_PATH}")
|
||||
# Verify we got actual paths, not just filenames
|
||||
if(IS_ABSOLUTE "${LIBSTDCPP_A_PATH}" AND IS_ABSOLUTE "${LIBGCC_A_PATH}")
|
||||
set(STATIC_LIBS_FOUND TRUE)
|
||||
message(STATUS "Found static libraries: ${LIBSTDCPP_A_PATH}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(STATIC_LIBS_FOUND)
|
||||
# Both static libraries found - use them
|
||||
target_link_options(zvec_c_api PRIVATE
|
||||
-static-libstdc++
|
||||
-static-libgcc
|
||||
)
|
||||
message(STATUS "Using static libstdc++ and libgcc")
|
||||
else()
|
||||
# Fall back to dynamic linking
|
||||
# Note: We still need to link the libraries, just not statically
|
||||
message(STATUS "Static libraries not found, using dynamic linking for libstdc++ and libgcc")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Include directories
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
176
tests/c/utils.c
176
tests/c/utils.c
|
|
@ -36,55 +36,55 @@ static char *strdup_safe(const char *str) {
|
|||
// Schema Creation Helper Functions Implementation
|
||||
// =============================================================================
|
||||
|
||||
ZVecCollectionSchema *zvec_test_create_temp_schema(void) {
|
||||
zvec_collection_schema_t *zvec_test_create_temp_schema(void) {
|
||||
// Create collection schema using C API
|
||||
ZVecCollectionSchema *schema = zvec_collection_schema_create("demo");
|
||||
zvec_collection_schema_t *schema = zvec_collection_schema_create("demo");
|
||||
zvec_collection_schema_set_max_doc_count_per_segment(schema, 1000);
|
||||
|
||||
// Create index parameters using new opaque pointer API
|
||||
ZVecIndexParams *invert_params =
|
||||
zvec_index_params_t *invert_params =
|
||||
zvec_index_params_create(ZVEC_INDEX_TYPE_INVERT);
|
||||
zvec_index_params_set_invert_params(invert_params, true, true);
|
||||
|
||||
ZVecIndexParams *dense_hnsw_params =
|
||||
zvec_index_params_t *dense_hnsw_params =
|
||||
zvec_index_params_create(ZVEC_INDEX_TYPE_HNSW);
|
||||
zvec_index_params_set_metric_type(dense_hnsw_params, ZVEC_METRIC_TYPE_L2);
|
||||
zvec_index_params_set_hnsw_params(dense_hnsw_params, 16, 100);
|
||||
|
||||
ZVecIndexParams *sparse_hnsw_params =
|
||||
zvec_index_params_t *sparse_hnsw_params =
|
||||
zvec_index_params_create(ZVEC_INDEX_TYPE_HNSW);
|
||||
zvec_index_params_set_metric_type(sparse_hnsw_params, ZVEC_METRIC_TYPE_IP);
|
||||
zvec_index_params_set_hnsw_params(sparse_hnsw_params, 16, 100);
|
||||
|
||||
ZVecIndexParams *name_invert_params =
|
||||
zvec_index_params_t *name_invert_params =
|
||||
zvec_index_params_create(ZVEC_INDEX_TYPE_INVERT);
|
||||
zvec_index_params_set_invert_params(name_invert_params, false, false);
|
||||
|
||||
// Create and add fields
|
||||
ZVecFieldSchema *id_field =
|
||||
zvec_field_schema_t *id_field =
|
||||
zvec_field_schema_create("id", ZVEC_DATA_TYPE_INT64, false, 0);
|
||||
zvec_field_schema_set_index_params(id_field, invert_params);
|
||||
zvec_collection_schema_add_field(schema, id_field);
|
||||
|
||||
// Create name field (inverted index without optimization)
|
||||
ZVecFieldSchema *name_field =
|
||||
zvec_field_schema_t *name_field =
|
||||
zvec_field_schema_create("name", ZVEC_DATA_TYPE_STRING, false, 0);
|
||||
zvec_field_schema_set_index_params(name_field, name_invert_params);
|
||||
zvec_collection_schema_add_field(schema, name_field);
|
||||
|
||||
// Create weight field (no index)
|
||||
ZVecFieldSchema *weight_field =
|
||||
zvec_field_schema_t *weight_field =
|
||||
zvec_field_schema_create("weight", ZVEC_DATA_TYPE_FLOAT, true, 0);
|
||||
zvec_collection_schema_add_field(schema, weight_field);
|
||||
|
||||
// Create dense field (HNSW index)
|
||||
ZVecFieldSchema *dense_field =
|
||||
zvec_field_schema_t *dense_field =
|
||||
zvec_field_schema_create("dense", ZVEC_DATA_TYPE_VECTOR_FP32, false, 128);
|
||||
zvec_field_schema_set_index_params(dense_field, dense_hnsw_params);
|
||||
zvec_collection_schema_add_field(schema, dense_field);
|
||||
|
||||
// Create sparse field (HNSW index)
|
||||
ZVecFieldSchema *sparse_field = zvec_field_schema_create(
|
||||
zvec_field_schema_t *sparse_field = zvec_field_schema_create(
|
||||
"sparse", ZVEC_DATA_TYPE_SPARSE_VECTOR_FP32, false, 0);
|
||||
zvec_field_schema_set_index_params(sparse_field, sparse_hnsw_params);
|
||||
zvec_collection_schema_add_field(schema, sparse_field);
|
||||
|
|
@ -98,40 +98,41 @@ ZVecCollectionSchema *zvec_test_create_temp_schema(void) {
|
|||
return schema;
|
||||
}
|
||||
|
||||
ZVecCollectionSchema *zvec_test_create_scalar_schema(void) {
|
||||
zvec_collection_schema_t *zvec_test_create_scalar_schema(void) {
|
||||
// Create collection schema using C API
|
||||
ZVecCollectionSchema *schema = zvec_collection_schema_create("demo");
|
||||
zvec_collection_schema_t *schema = zvec_collection_schema_create("demo");
|
||||
|
||||
// Create fields
|
||||
ZVecFieldSchema *int32_field =
|
||||
zvec_field_schema_t *int32_field =
|
||||
zvec_field_schema_create("int32", ZVEC_DATA_TYPE_INT32, false, 0);
|
||||
zvec_collection_schema_add_field(schema, int32_field);
|
||||
|
||||
ZVecFieldSchema *string_field =
|
||||
zvec_field_schema_t *string_field =
|
||||
zvec_field_schema_create("string", ZVEC_DATA_TYPE_STRING, false, 0);
|
||||
zvec_collection_schema_add_field(schema, string_field);
|
||||
|
||||
return schema;
|
||||
}
|
||||
|
||||
ZVecCollectionSchema *zvec_test_create_normal_schema(
|
||||
bool nullable, const char *name, const ZVecIndexParams *scalar_index_params,
|
||||
const ZVecIndexParams *vector_index_params, uint64_t max_doc_count) {
|
||||
zvec_collection_schema_t *zvec_test_create_normal_schema(
|
||||
bool nullable, const char *name,
|
||||
const zvec_index_params_t *scalar_index_params,
|
||||
const zvec_index_params_t *vector_index_params, uint64_t max_doc_count) {
|
||||
// Create collection schema using C API
|
||||
ZVecCollectionSchema *schema =
|
||||
zvec_collection_schema_t *schema =
|
||||
zvec_collection_schema_create(name ? name : "demo");
|
||||
zvec_collection_schema_set_max_doc_count_per_segment(schema, max_doc_count);
|
||||
|
||||
// Create scalar fields (8)
|
||||
const char *scalar_names[] = {"int32", "string", "uint32", "bool",
|
||||
"float", "double", "int64", "uint64"};
|
||||
ZVecDataType scalar_types[] = {ZVEC_DATA_TYPE_INT32, ZVEC_DATA_TYPE_STRING,
|
||||
ZVEC_DATA_TYPE_UINT32, ZVEC_DATA_TYPE_BOOL,
|
||||
ZVEC_DATA_TYPE_FLOAT, ZVEC_DATA_TYPE_DOUBLE,
|
||||
ZVEC_DATA_TYPE_INT64, ZVEC_DATA_TYPE_UINT64};
|
||||
zvec_data_type_t scalar_types[] = {
|
||||
ZVEC_DATA_TYPE_INT32, ZVEC_DATA_TYPE_STRING, ZVEC_DATA_TYPE_UINT32,
|
||||
ZVEC_DATA_TYPE_BOOL, ZVEC_DATA_TYPE_FLOAT, ZVEC_DATA_TYPE_DOUBLE,
|
||||
ZVEC_DATA_TYPE_INT64, ZVEC_DATA_TYPE_UINT64};
|
||||
|
||||
for (int i = 0; i < 8; i++) {
|
||||
ZVecFieldSchema *field =
|
||||
zvec_field_schema_t *field =
|
||||
zvec_field_schema_create(scalar_names[i], scalar_types[i], nullable, 0);
|
||||
if (scalar_index_params) {
|
||||
zvec_field_schema_set_index_params(field, scalar_index_params);
|
||||
|
|
@ -143,14 +144,14 @@ ZVecCollectionSchema *zvec_test_create_normal_schema(
|
|||
const char *array_names[] = {"array_int32", "array_string", "array_uint32",
|
||||
"array_bool", "array_float", "array_double",
|
||||
"array_int64", "array_uint64"};
|
||||
ZVecDataType array_types[] = {
|
||||
zvec_data_type_t array_types[] = {
|
||||
ZVEC_DATA_TYPE_ARRAY_INT32, ZVEC_DATA_TYPE_ARRAY_STRING,
|
||||
ZVEC_DATA_TYPE_ARRAY_UINT32, ZVEC_DATA_TYPE_ARRAY_BOOL,
|
||||
ZVEC_DATA_TYPE_ARRAY_FLOAT, ZVEC_DATA_TYPE_ARRAY_DOUBLE,
|
||||
ZVEC_DATA_TYPE_ARRAY_INT64, ZVEC_DATA_TYPE_ARRAY_UINT64};
|
||||
|
||||
for (int i = 0; i < 8; i++) {
|
||||
ZVecFieldSchema *field =
|
||||
zvec_field_schema_t *field =
|
||||
zvec_field_schema_create(array_names[i], array_types[i], nullable, 0);
|
||||
if (scalar_index_params) {
|
||||
zvec_field_schema_set_index_params(field, scalar_index_params);
|
||||
|
|
@ -160,38 +161,38 @@ ZVecCollectionSchema *zvec_test_create_normal_schema(
|
|||
|
||||
// Create vector fields (5)
|
||||
// dense vectors
|
||||
ZVecFieldSchema *dense_fp32 = zvec_field_schema_create(
|
||||
zvec_field_schema_t *dense_fp32 = zvec_field_schema_create(
|
||||
"dense_fp32", ZVEC_DATA_TYPE_VECTOR_FP32, false, 128);
|
||||
if (vector_index_params) {
|
||||
zvec_field_schema_set_index_params(dense_fp32, vector_index_params);
|
||||
}
|
||||
zvec_collection_schema_add_field(schema, dense_fp32);
|
||||
|
||||
ZVecFieldSchema *dense_fp16 = zvec_field_schema_create(
|
||||
zvec_field_schema_t *dense_fp16 = zvec_field_schema_create(
|
||||
"dense_fp16", ZVEC_DATA_TYPE_VECTOR_FP16, false, 128);
|
||||
ZVecIndexParams *flat_params1 = zvec_test_create_default_flat_params();
|
||||
zvec_index_params_t *flat_params1 = zvec_test_create_default_flat_params();
|
||||
zvec_field_schema_set_index_params(dense_fp16, flat_params1);
|
||||
zvec_index_params_destroy(flat_params1);
|
||||
zvec_collection_schema_add_field(schema, dense_fp16);
|
||||
|
||||
ZVecFieldSchema *dense_int8 = zvec_field_schema_create(
|
||||
zvec_field_schema_t *dense_int8 = zvec_field_schema_create(
|
||||
"dense_int8", ZVEC_DATA_TYPE_VECTOR_INT8, false, 128);
|
||||
ZVecIndexParams *flat_params2 = zvec_test_create_default_flat_params();
|
||||
zvec_index_params_t *flat_params2 = zvec_test_create_default_flat_params();
|
||||
zvec_field_schema_set_index_params(dense_int8, flat_params2);
|
||||
zvec_index_params_destroy(flat_params2);
|
||||
zvec_collection_schema_add_field(schema, dense_int8);
|
||||
|
||||
// sparse vectors
|
||||
ZVecFieldSchema *sparse_fp32 = zvec_field_schema_create(
|
||||
zvec_field_schema_t *sparse_fp32 = zvec_field_schema_create(
|
||||
"sparse_fp32", ZVEC_DATA_TYPE_SPARSE_VECTOR_FP32, false, 0);
|
||||
if (vector_index_params) {
|
||||
zvec_field_schema_set_index_params(sparse_fp32, vector_index_params);
|
||||
}
|
||||
zvec_collection_schema_add_field(schema, sparse_fp32);
|
||||
|
||||
ZVecFieldSchema *sparse_fp16 = zvec_field_schema_create(
|
||||
zvec_field_schema_t *sparse_fp16 = zvec_field_schema_create(
|
||||
"sparse_fp16", ZVEC_DATA_TYPE_SPARSE_VECTOR_FP16, false, 0);
|
||||
ZVecIndexParams *flat_params3 = zvec_test_create_default_flat_params();
|
||||
zvec_index_params_t *flat_params3 = zvec_test_create_default_flat_params();
|
||||
zvec_field_schema_set_index_params(sparse_fp16, flat_params3);
|
||||
zvec_index_params_destroy(flat_params3);
|
||||
zvec_collection_schema_add_field(schema, sparse_fp16);
|
||||
|
|
@ -199,25 +200,25 @@ ZVecCollectionSchema *zvec_test_create_normal_schema(
|
|||
return schema;
|
||||
}
|
||||
|
||||
ZVecCollectionSchema *zvec_test_create_schema_with_scalar_index(
|
||||
zvec_collection_schema_t *zvec_test_create_schema_with_scalar_index(
|
||||
bool nullable, bool enable_optimize, const char *name) {
|
||||
ZVecIndexParams *invert_params =
|
||||
zvec_index_params_t *invert_params =
|
||||
zvec_test_create_default_invert_params(enable_optimize);
|
||||
ZVecCollectionSchema *schema =
|
||||
zvec_collection_schema_t *schema =
|
||||
zvec_test_create_normal_schema(nullable, name, invert_params, NULL, 1000);
|
||||
free(invert_params);
|
||||
return schema;
|
||||
}
|
||||
|
||||
ZVecCollectionSchema *zvec_test_create_schema_with_vector_index(
|
||||
zvec_collection_schema_t *zvec_test_create_schema_with_vector_index(
|
||||
bool nullable, const char *name,
|
||||
const ZVecIndexParams *vector_index_params) {
|
||||
ZVecIndexParams *default_params = NULL;
|
||||
const zvec_index_params_t *vector_index_params) {
|
||||
zvec_index_params_t *default_params = NULL;
|
||||
if (!vector_index_params) {
|
||||
default_params = zvec_test_create_default_hnsw_params();
|
||||
}
|
||||
|
||||
ZVecCollectionSchema *schema = zvec_test_create_normal_schema(
|
||||
zvec_collection_schema_t *schema = zvec_test_create_normal_schema(
|
||||
nullable, name, NULL,
|
||||
vector_index_params ? vector_index_params : default_params, 1000);
|
||||
|
||||
|
|
@ -228,7 +229,7 @@ ZVecCollectionSchema *zvec_test_create_schema_with_vector_index(
|
|||
return schema;
|
||||
}
|
||||
|
||||
ZVecCollectionSchema *zvec_test_create_schema_with_max_doc_count(
|
||||
zvec_collection_schema_t *zvec_test_create_schema_with_max_doc_count(
|
||||
uint64_t doc_count) {
|
||||
return zvec_test_create_normal_schema(false, "demo", NULL, NULL, doc_count);
|
||||
}
|
||||
|
|
@ -250,11 +251,11 @@ uint64_t zvec_test_extract_doc_id(const char *pk) {
|
|||
return strtoull(pk + 3, NULL, 10);
|
||||
}
|
||||
|
||||
ZVecDoc *zvec_test_create_doc(uint64_t doc_id,
|
||||
const ZVecCollectionSchema *schema,
|
||||
const char *pk) {
|
||||
zvec_doc_t *zvec_test_create_doc(uint64_t doc_id,
|
||||
const zvec_collection_schema_t *schema,
|
||||
const char *pk) {
|
||||
if (!schema) return NULL;
|
||||
ZVecDoc *doc = zvec_doc_create();
|
||||
zvec_doc_t *doc = zvec_doc_create();
|
||||
if (!doc) return NULL;
|
||||
|
||||
// Set primary key
|
||||
|
|
@ -267,7 +268,7 @@ ZVecDoc *zvec_test_create_doc(uint64_t doc_id,
|
|||
// Create test data for each field
|
||||
const char **field_names = NULL;
|
||||
size_t field_count = 0;
|
||||
ZVecErrorCode ret = zvec_collection_schema_get_all_field_names(
|
||||
zvec_error_code_t ret = zvec_collection_schema_get_all_field_names(
|
||||
schema, &field_names, &field_count);
|
||||
if (ret != ZVEC_OK || !field_names) {
|
||||
zvec_doc_destroy(doc);
|
||||
|
|
@ -276,10 +277,10 @@ ZVecDoc *zvec_test_create_doc(uint64_t doc_id,
|
|||
|
||||
for (size_t i = 0; i < field_count; i++) {
|
||||
const char *field_name = field_names[i];
|
||||
const ZVecFieldSchema *field =
|
||||
const zvec_field_schema_t *field =
|
||||
zvec_collection_schema_get_field(schema, field_name);
|
||||
if (!field) continue;
|
||||
ZVecDataType field_type = zvec_field_schema_get_data_type(field);
|
||||
zvec_data_type_t field_type = zvec_field_schema_get_data_type(field);
|
||||
uint32_t field_dimension = zvec_field_schema_get_dimension(field);
|
||||
|
||||
switch (field_type) {
|
||||
|
|
@ -579,11 +580,11 @@ ZVecDoc *zvec_test_create_doc(uint64_t doc_id,
|
|||
return doc;
|
||||
}
|
||||
|
||||
ZVecDoc *zvec_test_create_doc_null(uint64_t doc_id,
|
||||
const ZVecCollectionSchema *schema,
|
||||
const char *pk) {
|
||||
zvec_doc_t *zvec_test_create_doc_null(uint64_t doc_id,
|
||||
const zvec_collection_schema_t *schema,
|
||||
const char *pk) {
|
||||
// Reuse create_doc function, but only process vector fields
|
||||
ZVecDoc *doc = zvec_doc_create();
|
||||
zvec_doc_t *doc = zvec_doc_create();
|
||||
if (!doc) return NULL;
|
||||
|
||||
// Set primary key
|
||||
|
|
@ -596,7 +597,7 @@ ZVecDoc *zvec_test_create_doc_null(uint64_t doc_id,
|
|||
// Only create data for vector fields
|
||||
const char **field_names = NULL;
|
||||
size_t field_count = 0;
|
||||
ZVecErrorCode ret = zvec_collection_schema_get_all_field_names(
|
||||
zvec_error_code_t ret = zvec_collection_schema_get_all_field_names(
|
||||
schema, &field_names, &field_count);
|
||||
if (ret != ZVEC_OK || !field_names) {
|
||||
zvec_doc_destroy(doc);
|
||||
|
|
@ -605,10 +606,10 @@ ZVecDoc *zvec_test_create_doc_null(uint64_t doc_id,
|
|||
|
||||
for (size_t i = 0; i < field_count; i++) {
|
||||
const char *field_name = field_names[i];
|
||||
const ZVecFieldSchema *field =
|
||||
const zvec_field_schema_t *field =
|
||||
zvec_collection_schema_get_field(schema, field_name);
|
||||
if (!field) continue;
|
||||
ZVecDataType field_type = zvec_field_schema_get_data_type(field);
|
||||
zvec_data_type_t field_type = zvec_field_schema_get_data_type(field);
|
||||
uint32_t field_dimension = zvec_field_schema_get_dimension(field);
|
||||
|
||||
// Only process specific vector type fields
|
||||
|
|
@ -620,7 +621,7 @@ ZVecDoc *zvec_test_create_doc_null(uint64_t doc_id,
|
|||
continue;
|
||||
}
|
||||
|
||||
ZVecErrorCode err = ZVEC_OK;
|
||||
zvec_error_code_t err = ZVEC_OK;
|
||||
|
||||
switch (field_type) {
|
||||
case ZVEC_DATA_TYPE_VECTOR_FP32: {
|
||||
|
|
@ -743,11 +744,10 @@ ZVecDoc *zvec_test_create_doc_null(uint64_t doc_id,
|
|||
return doc;
|
||||
}
|
||||
|
||||
ZVecDoc *zvec_test_create_doc_with_fields(uint64_t doc_id,
|
||||
const char **field_names,
|
||||
const ZVecDataType *field_types,
|
||||
size_t field_count, const char *pk) {
|
||||
ZVecDoc *doc = zvec_doc_create();
|
||||
zvec_doc_t *zvec_test_create_doc_with_fields(
|
||||
uint64_t doc_id, const char **field_names,
|
||||
const zvec_data_type_t *field_types, size_t field_count, const char *pk) {
|
||||
zvec_doc_t *doc = zvec_doc_create();
|
||||
if (!doc) return NULL;
|
||||
|
||||
// Set primary key
|
||||
|
|
@ -759,7 +759,7 @@ ZVecDoc *zvec_test_create_doc_with_fields(uint64_t doc_id,
|
|||
|
||||
// Create data for specified fields
|
||||
for (size_t i = 0; i < field_count; i++) {
|
||||
ZVecErrorCode err = ZVEC_OK;
|
||||
zvec_error_code_t err = ZVEC_OK;
|
||||
|
||||
switch (field_types[i]) {
|
||||
case ZVEC_DATA_TYPE_INT32:
|
||||
|
|
@ -807,8 +807,8 @@ ZVecDoc *zvec_test_create_doc_with_fields(uint64_t doc_id,
|
|||
// Index Parameter Creation Helper Functions Implementation
|
||||
// =============================================================================
|
||||
|
||||
ZVecIndexParams *zvec_test_create_default_hnsw_params(void) {
|
||||
ZVecIndexParams *params = zvec_index_params_create(ZVEC_INDEX_TYPE_HNSW);
|
||||
zvec_index_params_t *zvec_test_create_default_hnsw_params(void) {
|
||||
zvec_index_params_t *params = zvec_index_params_create(ZVEC_INDEX_TYPE_HNSW);
|
||||
if (!params) return NULL;
|
||||
|
||||
zvec_index_params_set_metric_type(params, ZVEC_METRIC_TYPE_IP);
|
||||
|
|
@ -817,8 +817,8 @@ ZVecIndexParams *zvec_test_create_default_hnsw_params(void) {
|
|||
return params;
|
||||
}
|
||||
|
||||
ZVecIndexParams *zvec_test_create_default_flat_params(void) {
|
||||
ZVecIndexParams *params = zvec_index_params_create(ZVEC_INDEX_TYPE_FLAT);
|
||||
zvec_index_params_t *zvec_test_create_default_flat_params(void) {
|
||||
zvec_index_params_t *params = zvec_index_params_create(ZVEC_INDEX_TYPE_FLAT);
|
||||
if (!params) return NULL;
|
||||
|
||||
zvec_index_params_set_metric_type(params, ZVEC_METRIC_TYPE_IP);
|
||||
|
|
@ -826,8 +826,10 @@ ZVecIndexParams *zvec_test_create_default_flat_params(void) {
|
|||
return params;
|
||||
}
|
||||
|
||||
ZVecIndexParams *zvec_test_create_default_invert_params(bool enable_optimize) {
|
||||
ZVecIndexParams *params = zvec_index_params_create(ZVEC_INDEX_TYPE_INVERT);
|
||||
zvec_index_params_t *zvec_test_create_default_invert_params(
|
||||
bool enable_optimize) {
|
||||
zvec_index_params_t *params =
|
||||
zvec_index_params_create(ZVEC_INDEX_TYPE_INVERT);
|
||||
if (!params) return NULL;
|
||||
|
||||
zvec_index_params_set_invert_params(params, enable_optimize, enable_optimize);
|
||||
|
|
@ -839,18 +841,18 @@ ZVecIndexParams *zvec_test_create_default_invert_params(bool enable_optimize) {
|
|||
// Field Schema Creation Helper Functions Implementation
|
||||
// =============================================================================
|
||||
|
||||
ZVecFieldSchema *zvec_test_create_scalar_field(
|
||||
const char *name, ZVecDataType data_type, bool nullable,
|
||||
const ZVecIndexParams *invert_params) {
|
||||
zvec_field_schema_t *zvec_test_create_scalar_field(
|
||||
const char *name, zvec_data_type_t data_type, bool nullable,
|
||||
const zvec_index_params_t *invert_params) {
|
||||
// Use the public API to create the field
|
||||
ZVecFieldSchema *field =
|
||||
zvec_field_schema_t *field =
|
||||
zvec_field_schema_create(name, data_type, nullable, 0);
|
||||
if (!field) return NULL;
|
||||
|
||||
if (invert_params) {
|
||||
// Clone the index params using setter API
|
||||
ZVecIndexType type = zvec_index_params_get_type(invert_params);
|
||||
ZVecIndexParams *cloned_params = zvec_index_params_create(type);
|
||||
zvec_index_type_t type = zvec_index_params_get_type(invert_params);
|
||||
zvec_index_params_t *cloned_params = zvec_index_params_create(type);
|
||||
if (cloned_params) {
|
||||
bool enable_range_opt, enable_wildcard;
|
||||
zvec_index_params_get_invert_params(invert_params, &enable_range_opt,
|
||||
|
|
@ -865,18 +867,18 @@ ZVecFieldSchema *zvec_test_create_scalar_field(
|
|||
return field;
|
||||
}
|
||||
|
||||
ZVecFieldSchema *zvec_test_create_vector_field(
|
||||
const char *name, ZVecDataType data_type, uint32_t dimension, bool nullable,
|
||||
const ZVecIndexParams *vector_index_params) {
|
||||
zvec_field_schema_t *zvec_test_create_vector_field(
|
||||
const char *name, zvec_data_type_t data_type, uint32_t dimension,
|
||||
bool nullable, const zvec_index_params_t *vector_index_params) {
|
||||
// Use the public API to create the field
|
||||
ZVecFieldSchema *field =
|
||||
zvec_field_schema_t *field =
|
||||
zvec_field_schema_create(name, data_type, nullable, dimension);
|
||||
if (!field) return NULL;
|
||||
|
||||
if (vector_index_params) {
|
||||
// Clone the index params using setter API
|
||||
ZVecIndexType type = zvec_index_params_get_type(vector_index_params);
|
||||
ZVecIndexParams *cloned_params = zvec_index_params_create(type);
|
||||
zvec_index_type_t type = zvec_index_params_get_type(vector_index_params);
|
||||
zvec_index_params_t *cloned_params = zvec_index_params_create(type);
|
||||
if (cloned_params) {
|
||||
int m, ef_construction;
|
||||
m = zvec_index_params_get_hnsw_m(vector_index_params);
|
||||
|
|
@ -891,18 +893,18 @@ ZVecFieldSchema *zvec_test_create_vector_field(
|
|||
return field;
|
||||
}
|
||||
|
||||
ZVecFieldSchema *zvec_test_create_sparse_vector_field(
|
||||
const char *name, ZVecDataType data_type, bool nullable,
|
||||
const ZVecIndexParams *vector_index_params) {
|
||||
zvec_field_schema_t *zvec_test_create_sparse_vector_field(
|
||||
const char *name, zvec_data_type_t data_type, bool nullable,
|
||||
const zvec_index_params_t *vector_index_params) {
|
||||
// Use the public API to create the field
|
||||
ZVecFieldSchema *field =
|
||||
zvec_field_schema_t *field =
|
||||
zvec_field_schema_create(name, data_type, nullable, 0);
|
||||
if (!field) return NULL;
|
||||
|
||||
if (vector_index_params) {
|
||||
// Clone the index params using setter API
|
||||
ZVecIndexType type = zvec_index_params_get_type(vector_index_params);
|
||||
ZVecIndexParams *cloned_params = zvec_index_params_create(type);
|
||||
zvec_index_type_t type = zvec_index_params_get_type(vector_index_params);
|
||||
zvec_index_params_t *cloned_params = zvec_index_params_create(type);
|
||||
if (cloned_params) {
|
||||
int m, ef_construction;
|
||||
m = zvec_index_params_get_hnsw_m(vector_index_params);
|
||||
|
|
|
|||
|
|
@ -32,18 +32,18 @@ extern "C" {
|
|||
* @brief Create temporary test schema
|
||||
* Contains basic scalar fields and vector fields
|
||||
*
|
||||
* @return ZVecCollectionSchema* Created schema pointer, needs to be released by
|
||||
* calling zvec_collection_schema_cleanup
|
||||
* @return zvec_collection_schema_t* Created schema pointer, needs to be
|
||||
* released by calling zvec_collection_schema_cleanup
|
||||
*/
|
||||
ZVecCollectionSchema *zvec_test_create_temp_schema(void);
|
||||
zvec_collection_schema_t *zvec_test_create_temp_schema(void);
|
||||
|
||||
/**
|
||||
* @brief Create pure scalar schema
|
||||
* Contains only scalar fields (int32, string)
|
||||
*
|
||||
* @return ZVecCollectionSchema* Created schema pointer
|
||||
* @return zvec_collection_schema_t* Created schema pointer
|
||||
*/
|
||||
ZVecCollectionSchema *zvec_test_create_scalar_schema(void);
|
||||
zvec_collection_schema_t *zvec_test_create_scalar_schema(void);
|
||||
|
||||
/**
|
||||
* @brief Create full-featured schema
|
||||
|
|
@ -54,11 +54,12 @@ ZVecCollectionSchema *zvec_test_create_scalar_schema(void);
|
|||
* @param scalar_index_params Scalar index parameters (can be NULL)
|
||||
* @param vector_index_params Vector index parameters (can be NULL)
|
||||
* @param max_doc_count Maximum documents per segment
|
||||
* @return ZVecCollectionSchema* Created schema pointer
|
||||
* @return zvec_collection_schema_t* Created schema pointer
|
||||
*/
|
||||
ZVecCollectionSchema *zvec_test_create_normal_schema(
|
||||
bool nullable, const char *name, const ZVecIndexParams *scalar_index_params,
|
||||
const ZVecIndexParams *vector_index_params, uint64_t max_doc_count);
|
||||
zvec_collection_schema_t *zvec_test_create_normal_schema(
|
||||
bool nullable, const char *name,
|
||||
const zvec_index_params_t *scalar_index_params,
|
||||
const zvec_index_params_t *vector_index_params, uint64_t max_doc_count);
|
||||
|
||||
/**
|
||||
* @brief Create schema with scalar index
|
||||
|
|
@ -66,9 +67,9 @@ ZVecCollectionSchema *zvec_test_create_normal_schema(
|
|||
* @param nullable Whether to allow null values
|
||||
* @param enable_optimize Whether to enable optimization
|
||||
* @param name Schema name
|
||||
* @return ZVecCollectionSchema* Created schema pointer
|
||||
* @return zvec_collection_schema_t* Created schema pointer
|
||||
*/
|
||||
ZVecCollectionSchema *zvec_test_create_schema_with_scalar_index(
|
||||
zvec_collection_schema_t *zvec_test_create_schema_with_scalar_index(
|
||||
bool nullable, bool enable_optimize, const char *name);
|
||||
|
||||
/**
|
||||
|
|
@ -78,19 +79,19 @@ ZVecCollectionSchema *zvec_test_create_schema_with_scalar_index(
|
|||
* @param name Schema name
|
||||
* @param vector_index_params Vector index parameters (can be NULL, uses default
|
||||
* HNSW parameters)
|
||||
* @return ZVecCollectionSchema* Created schema pointer
|
||||
* @return zvec_collection_schema_t* Created schema pointer
|
||||
*/
|
||||
ZVecCollectionSchema *zvec_test_create_schema_with_vector_index(
|
||||
zvec_collection_schema_t *zvec_test_create_schema_with_vector_index(
|
||||
bool nullable, const char *name,
|
||||
const ZVecIndexParams *vector_index_params);
|
||||
const zvec_index_params_t *vector_index_params);
|
||||
|
||||
/**
|
||||
* @brief Create schema with specified maximum document count
|
||||
*
|
||||
* @param doc_count Maximum documents per segment
|
||||
* @return ZVecCollectionSchema* Created schema pointer
|
||||
* @return zvec_collection_schema_t* Created schema pointer
|
||||
*/
|
||||
ZVecCollectionSchema *zvec_test_create_schema_with_max_doc_count(
|
||||
zvec_collection_schema_t *zvec_test_create_schema_with_max_doc_count(
|
||||
uint64_t doc_count);
|
||||
|
||||
// =============================================================================
|
||||
|
|
@ -113,12 +114,12 @@ char *zvec_test_make_pk(uint64_t doc_id);
|
|||
* @param doc_id Document ID
|
||||
* @param schema Schema pointer
|
||||
* @param pk Primary key (can be NULL, auto-generated)
|
||||
* @return ZVecDoc* Created document pointer, needs to be released by calling
|
||||
* @return zvec_doc_t* Created document pointer, needs to be released by calling
|
||||
* zvec_doc_destroy
|
||||
*/
|
||||
ZVecDoc *zvec_test_create_doc(uint64_t doc_id,
|
||||
const ZVecCollectionSchema *schema,
|
||||
const char *pk);
|
||||
zvec_doc_t *zvec_test_create_doc(uint64_t doc_id,
|
||||
const zvec_collection_schema_t *schema,
|
||||
const char *pk);
|
||||
|
||||
/**
|
||||
* @brief Create partial null document
|
||||
|
|
@ -127,11 +128,11 @@ ZVecDoc *zvec_test_create_doc(uint64_t doc_id,
|
|||
* @param doc_id Document ID
|
||||
* @param schema Schema pointer
|
||||
* @param pk Primary key (can be NULL, auto-generated)
|
||||
* @return ZVecDoc* Created document pointer
|
||||
* @return zvec_doc_t* Created document pointer
|
||||
*/
|
||||
ZVecDoc *zvec_test_create_doc_null(uint64_t doc_id,
|
||||
const ZVecCollectionSchema *schema,
|
||||
const char *pk);
|
||||
zvec_doc_t *zvec_test_create_doc_null(uint64_t doc_id,
|
||||
const zvec_collection_schema_t *schema,
|
||||
const char *pk);
|
||||
|
||||
/**
|
||||
* @brief Create document with specified fields
|
||||
|
|
@ -142,12 +143,11 @@ ZVecDoc *zvec_test_create_doc_null(uint64_t doc_id,
|
|||
* @param field_types Field type array
|
||||
* @param field_count Number of fields
|
||||
* @param pk Primary key (can be NULL, auto-generated)
|
||||
* @return ZVecDoc* Created document pointer
|
||||
* @return zvec_doc_t* Created document pointer
|
||||
*/
|
||||
ZVecDoc *zvec_test_create_doc_with_fields(uint64_t doc_id,
|
||||
const char **field_names,
|
||||
const ZVecDataType *field_types,
|
||||
size_t field_count, const char *pk);
|
||||
zvec_doc_t *zvec_test_create_doc_with_fields(
|
||||
uint64_t doc_id, const char **field_names,
|
||||
const zvec_data_type_t *field_types, size_t field_count, const char *pk);
|
||||
|
||||
// =============================================================================
|
||||
// Index Parameter Creation Helper Functions
|
||||
|
|
@ -156,24 +156,25 @@ ZVecDoc *zvec_test_create_doc_with_fields(uint64_t doc_id,
|
|||
/**
|
||||
* @brief Create default HNSW index parameters
|
||||
*
|
||||
* @return ZVecIndexParams* Created parameter pointer
|
||||
* @return zvec_index_params_t* Created parameter pointer
|
||||
*/
|
||||
ZVecIndexParams *zvec_test_create_default_hnsw_params(void);
|
||||
zvec_index_params_t *zvec_test_create_default_hnsw_params(void);
|
||||
|
||||
/**
|
||||
* @brief Create default Flat index parameters
|
||||
*
|
||||
* @return ZVecIndexParams* Created parameter pointer
|
||||
* @return zvec_index_params_t* Created parameter pointer
|
||||
*/
|
||||
ZVecIndexParams *zvec_test_create_default_flat_params(void);
|
||||
zvec_index_params_t *zvec_test_create_default_flat_params(void);
|
||||
|
||||
/**
|
||||
* @brief Create default scalar index parameters
|
||||
*
|
||||
* @param enable_optimize Whether to enable optimization
|
||||
* @return ZVecIndexParams* Created parameter pointer
|
||||
* @return zvec_index_params_t* Created parameter pointer
|
||||
*/
|
||||
ZVecIndexParams *zvec_test_create_default_invert_params(bool enable_optimize);
|
||||
zvec_index_params_t *zvec_test_create_default_invert_params(
|
||||
bool enable_optimize);
|
||||
|
||||
// =============================================================================
|
||||
// Field Schema Creation Helper Functions
|
||||
|
|
@ -186,12 +187,12 @@ ZVecIndexParams *zvec_test_create_default_invert_params(bool enable_optimize);
|
|||
* @param data_type Data type
|
||||
* @param nullable Whether to allow null values
|
||||
* @param invert_params Scalar index parameters (can be NULL)
|
||||
* @return ZVecFieldSchema* Created field schema pointer, needs to be released
|
||||
* by calling free()
|
||||
* @return zvec_field_schema_t* Created field schema pointer, needs to be
|
||||
* released by calling free()
|
||||
*/
|
||||
ZVecFieldSchema *zvec_test_create_scalar_field(
|
||||
const char *name, ZVecDataType data_type, bool nullable,
|
||||
const ZVecIndexParams *invert_params);
|
||||
zvec_field_schema_t *zvec_test_create_scalar_field(
|
||||
const char *name, zvec_data_type_t data_type, bool nullable,
|
||||
const zvec_index_params_t *invert_params);
|
||||
|
||||
/**
|
||||
* @brief Create vector field schema
|
||||
|
|
@ -201,11 +202,11 @@ ZVecFieldSchema *zvec_test_create_scalar_field(
|
|||
* @param dimension Vector dimension
|
||||
* @param nullable Whether to allow null values
|
||||
* @param vector_index_params Vector index parameters (can be NULL)
|
||||
* @return ZVecFieldSchema* Created field schema pointer
|
||||
* @return zvec_field_schema_t* Created field schema pointer
|
||||
*/
|
||||
ZVecFieldSchema *zvec_test_create_vector_field(
|
||||
const char *name, ZVecDataType data_type, uint32_t dimension, bool nullable,
|
||||
const ZVecIndexParams *vector_index_params);
|
||||
zvec_field_schema_t *zvec_test_create_vector_field(
|
||||
const char *name, zvec_data_type_t data_type, uint32_t dimension,
|
||||
bool nullable, const zvec_index_params_t *vector_index_params);
|
||||
|
||||
/**
|
||||
* @brief Create sparse vector field schema
|
||||
|
|
@ -214,11 +215,11 @@ ZVecFieldSchema *zvec_test_create_vector_field(
|
|||
* @param data_type Data type
|
||||
* @param nullable Whether to allow null values
|
||||
* @param vector_index_params Vector index parameters (can be NULL)
|
||||
* @return ZVecFieldSchema* Created field schema pointer
|
||||
* @return zvec_field_schema_t* Created field schema pointer
|
||||
*/
|
||||
ZVecFieldSchema *zvec_test_create_sparse_vector_field(
|
||||
const char *name, ZVecDataType data_type, bool nullable,
|
||||
const ZVecIndexParams *vector_index_params);
|
||||
zvec_field_schema_t *zvec_test_create_sparse_vector_field(
|
||||
const char *name, zvec_data_type_t data_type, bool nullable,
|
||||
const zvec_index_params_t *vector_index_params);
|
||||
|
||||
// =============================================================================
|
||||
// Memory Management Helper Functions
|
||||
|
|
|
|||
Loading…
Reference in New Issue