-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* First 5 vector search tests including some adjustments
- Loading branch information
1 parent
944210a
commit dca3435
Showing
9 changed files
with
277 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+1.49 MB
Objective-C/Tests/Support/databases/vectorsearch/words_db.cblite2/db.sqlite3
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// CBLWordEmbeddingModel.h | ||
// CBL_EE_ObjC | ||
// | ||
// Copyright (c) 2024 Couchbase, Inc. All rights reserved. | ||
// COUCHBASE CONFIDENTIAL -- part of Couchbase Lite Enterprise Edition | ||
// | ||
|
||
#import "CouchbaseLite.h" | ||
#import "CBLPrediction.h" | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface CBLWordEmbeddingModel : NSObject <CBLPredictiveModel> | ||
|
||
- (instancetype) init: (CBLDatabase*) database; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// | ||
// CBLWordEmbeddingModel.m | ||
// CBL_EE_ObjC | ||
// | ||
// Copyright (c) 2024 Couchbase, Inc. All rights reserved. | ||
// COUCHBASE CONFIDENTIAL -- part of Couchbase Lite Enterprise Edition | ||
// | ||
|
||
#import "CBLWordEmbeddingModel.h" | ||
|
||
@implementation CBLWordEmbeddingModel { | ||
CBLDatabase* _database; | ||
} | ||
|
||
- (instancetype) init: (CBLDatabase*)database { | ||
self = [super init]; | ||
if (self) { | ||
_database = database; | ||
} | ||
return self; | ||
} | ||
|
||
- (NSArray*) vectorForWord: (NSString*)word collection: (NSString*)collection { | ||
NSError* error; | ||
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; | ||
} | ||
|
||
|
||
- (CBLDictionary*) predict: (CBLDictionary*)input { | ||
NSString* inputWord = [input stringForKey: @"word"]; | ||
|
||
if (!inputWord) { | ||
NSLog(@"No word input !!!"); | ||
return nil; | ||
} | ||
|
||
NSArray* result = [self vectorForWord: inputWord collection: @"words"]; | ||
if (!result) { | ||
result = [self vectorForWord: inputWord collection: @"extwords"]; | ||
} | ||
|
||
if (!result) { | ||
return nil; | ||
} | ||
|
||
CBLMutableDictionary* output = [[CBLMutableDictionary alloc] init]; | ||
[output setValue: result forKey: @"vector"]; | ||
return output; | ||
} | ||
|
||
@end | ||
|
||
|
Oops, something went wrong.