Skip to content

Commit

Permalink
CBL-5432: Vector Index API Tests 8-10 [Obj-C] (#3243)
Browse files Browse the repository at this point in the history
* update litecore and fix NODISCARD

* update VS extension version

* fix WordModel constructor

* 10 tests ready
  • Loading branch information
velicuvlad authored Mar 4, 2024
1 parent 7b3acc3 commit 52ebcbb
Show file tree
Hide file tree
Showing 6 changed files with 321 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Objective-C/Internal/CBLCoreBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class C4Transaction {

~C4Transaction() {
if (_active)
c4db_endTransaction(_db, false, nullptr);
(void)c4db_endTransaction(_db, false, nullptr);
}

bool begin() {
Expand Down
5 changes: 4 additions & 1 deletion Objective-C/Tests/Util/CBLWordEmbeddingModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ NS_ASSUME_NONNULL_BEGIN

@interface CBLWordEmbeddingModel : NSObject <CBLPredictiveModel>

- (instancetype) init: (CBLDatabase*) database;
- (instancetype) initWithDatabase: (CBLDatabase*) database;

/** Not available */
- (instancetype) init NS_UNAVAILABLE;

@end

Expand Down
18 changes: 12 additions & 6 deletions Objective-C/Tests/Util/CBLWordEmbeddingModel.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,27 @@ @implementation CBLWordEmbeddingModel {
CBLDatabase* _database;
}

- (instancetype) init: (CBLDatabase*)database {
- (instancetype) initWithDatabase: (CBLDatabase*)database {
self = [super init];
if (self) {
_database = database;
}
return self;
}

- (NSArray*) vectorForWord: (NSString*)word collection: (NSString*)collection {
- (CBLArray*) vectorForWord: (NSString*)word collection: (NSString*)collection {
NSError* error;
NSString* sql = [NSString stringWithFormat: @"select vector from %@ where word = %@", collection, word];
NSString* sql = [NSString stringWithFormat: @"select vector from %@ where word = '%@'", collection, word];
CBLQuery* q = [_database createQuery: sql error: &error];
CBLQueryResultSet* rs = [q execute: &error];
NSArray* results = [rs allResults];
return results.count > 0 ? results[0][@"word"] : nil;
NSArray<CBLQueryResult*>* results = [rs allResults];

if (results.count == 0) {
return nil;
}

CBLQueryResult* result = results[0];
return [result arrayForKey: @"vector"];
}


Expand All @@ -38,7 +44,7 @@ - (CBLDictionary*) predict: (CBLDictionary*)input {
return nil;
}

NSArray* result = [self vectorForWord: inputWord collection: @"words"];
CBLArray* result = [self vectorForWord: inputWord collection: @"words"];
if (!result) {
result = [self vectorForWord: inputWord collection: @"extwords"];
}
Expand Down
Loading

0 comments on commit 52ebcbb

Please sign in to comment.