Skip to content

Commit

Permalink
fix build and test methods for limit
Browse files Browse the repository at this point in the history
  • Loading branch information
velicuvlad committed Jan 31, 2025
1 parent a7e1d41 commit 7e2e462
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 19 deletions.
10 changes: 5 additions & 5 deletions Objective-C/Tests/VectorSearchTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,22 @@ NS_ASSUME_NONNULL_BEGIN
/** For the test subclasses to override the default vector expression. */
- (NSString*) wordsQueryDefaultExpression;

- (NSString*) wordsQueryStringWithLimit: (NSUInteger)limit
- (NSString*) wordsQueryStringWithLimit: (NSInteger)limit
metric: (nullable NSString*)metric
vectorExpression: (nullable NSString*)vectorExpression
whereClause: (nullable NSString*)whereClause;

- (NSString*) wordsQueryStringWithLimit: (NSUInteger)limit;
- (NSString*) wordsQueryStringWithLimit: (NSInteger)limit;

- (CBLQueryResultSet*) executeWordsQueryWithLimit: (NSUInteger)limit
- (CBLQueryResultSet*) executeWordsQueryWithLimit: (NSInteger)limit
metric: (nullable NSString*)metric
vectorExpression: (nullable NSString*)vectorExpression
whereClause: (nullable NSString*)whereClause
checkTraining: (BOOL) checkTraining;

- (CBLQueryResultSet*) executeWordsQueryWithLimit: (NSUInteger)limit;
- (CBLQueryResultSet*) executeWordsQueryWithLimit: (NSInteger)limit;

- (CBLQueryResultSet*) executeWordsQueryNoTrainingCheckWithLimit: (NSUInteger)limit;
- (CBLQueryResultSet*) executeWordsQueryNoTrainingCheckWithLimit: (NSInteger)limit;

- (NSDictionary<NSString*, NSString*>*) toDocIDWordMap: (CBLQueryResultSet*)resultSet;

Expand Down
25 changes: 12 additions & 13 deletions Objective-C/Tests/VectorSearchTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ - (NSString*) wordsQueryDefaultExpression {
return @"vector";
}

- (NSString*) wordsQueryStringWithLimit: (NSUInteger)limit
- (NSString*) wordsQueryStringWithLimit: (NSInteger)limit
metric: (nullable NSString*)metric
vectorExpression: (nullable NSString*)vectorExpression
whereClause: (nullable NSString*)whereClause {
Expand All @@ -163,17 +163,16 @@ - (NSString*) wordsQueryStringWithLimit: (NSUInteger)limit
sql = [sql stringByAppendingFormat: @"ORDER BY APPROX_VECTOR_DISTANCE(%@, $vector) ", vectorExpression];
}


sql = [sql stringByAppendingFormat: @"LIMIT %lu", (unsigned long)limit];

sql = [sql stringByAppendingFormat: @"LIMIT %ld", (long)limit];

return sql;
}

- (NSString*) wordsQueryStringWithLimit: (NSUInteger)limit {
- (NSString*) wordsQueryStringWithLimit: (NSInteger)limit {
return [self wordsQueryStringWithLimit: limit metric: nil vectorExpression: nil whereClause: nil];
}

- (CBLQueryResultSet*) executeWordsQueryWithLimit: (NSUInteger)limit
- (CBLQueryResultSet*) executeWordsQueryWithLimit: (NSInteger)limit
metric: (NSString*)metric
vectorExpression: (NSString*)vectorExpression
whereClause: (NSString*)whereClause
Expand Down Expand Up @@ -203,16 +202,16 @@ - (CBLQueryResultSet*) executeWordsQueryWithLimit: (NSUInteger)limit
return rs;
}

- (CBLQueryResultSet*) executeWordsQueryWithLimit: (NSUInteger)limit {
return [self executeWordsQueryWithLimit: limit
- (CBLQueryResultSet*) executeWordsQueryWithLimit: (NSInteger)limit {
return [self executeWordsQueryWithLimit: limit
metric: nil
vectorExpression: nil
whereClause: nil
checkTraining: true];
}

- (CBLQueryResultSet*) executeWordsQueryNoTrainingCheckWithLimit: (NSUInteger)limit {
return [self executeWordsQueryWithLimit: limit
- (CBLQueryResultSet*) executeWordsQueryNoTrainingCheckWithLimit: (NSInteger)limit {
return [self executeWordsQueryWithLimit: limit
metric: nil
vectorExpression: nil
whereClause: nil
Expand Down Expand Up @@ -1177,17 +1176,17 @@ - (void) testVectorMatchLimitBoundary {
CBLVectorIndexConfiguration* config = VECTOR_INDEX_CONFIG(@"vector", 300, 8);
[self createWordsIndexWithConfig: config];

// Check valid query with 1 and 10000 set limit
// Check valid query with -1, 0, 1 and 10000 set limit
for (NSNumber* limit in @[@-1, @0, @1, @10000]) {
NSError* error;
NSString* sql = [self wordsQueryStringWithLimit: [limit unsignedIntegerValue]];
NSString* sql = [self wordsQueryStringWithLimit: [limit integerValue]];
Assert([self.wordDB createQuery: sql error: &error]);
AssertNil(error);
}

// Check if error thrown for wrong limit values
[self expectError: CBLErrorDomain code: CBLErrorInvalidQuery in: ^BOOL(NSError** err) {
NSString* sql = [self wordsQueryStringWithLimit: [@10001 unsignedIntegerValue]];
NSString* sql = [self wordsQueryStringWithLimit: 10001];
return [self.wordDB createQuery: sql error: err] != nil;
}];
}
Expand Down
2 changes: 1 addition & 1 deletion Swift/Tests/VectorSearchTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@ class VectorSearchTest_Main: VectorSearchTest {
let config = VectorIndexConfiguration(expression: "vector", dimensions: 300, centroids: 8)
try createWordsIndex(config: config)

// Check valid query with 1 and 10000 set limit
// Check valid query with -1, 0, 1 and 10000 set limit
for limit in [-1, 0, 1, 10000] {
_ = try executeWordsQuery(limit: limit)
}
Expand Down

0 comments on commit 7e2e462

Please sign in to comment.