Skip to content
This repository has been archived by the owner on Aug 25, 2024. It is now read-only.

Commit

Permalink
Couchbase-disable-test (#67)
Browse files Browse the repository at this point in the history
Disabled couchbase writer test

---------

Co-authored-by: benfrank241 <[email protected]>
  • Loading branch information
benfrank241 and benfrank241 authored Jun 14, 2024
1 parent 827f166 commit 7886587
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public List<Map<String, Object>> fetchData(String query, List<Object> params) {

private double computeCosineSimilarity(float[] vector1, double[] vector2) {
// Log the first 5 elements of each vector and the operation
log.info(
log.debug(
"Vector1 (first 5 elements): {}..., Vector2 (first 5 elements): {}..., Computing cosine similarity between vectors",
Arrays.toString(Arrays.copyOfRange(vector1, 0, 5)),
Arrays.toString(Arrays.copyOfRange(vector2, 0, 5)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,92 +106,71 @@ public void initialise(Map<String, Object> agentConfiguration) throws Exception
public CompletableFuture<Void> upsert(Record record, Map<String, Object> context) {

CompletableFuture<Void> handle = new CompletableFuture<>();
return CompletableFuture.runAsync(
() -> {
try {

MutableRecord mutableRecord =
recordToMutableRecord(record, true);

// Evaluate the ID using the idFunction
String docId =
idFunction != null
? (String) idFunction.evaluate(mutableRecord)
: null;

if (docId == null) {
throw new IllegalArgumentException(
"docId is null, cannot upsert document");
}

String bucketS =
bucketName != null
? (String) bucketName.evaluate(mutableRecord)
: null;
String scopeS =
scopeName != null
? (String) scopeName.evaluate(mutableRecord)
: null;
String collectionS =
collectionName != null
? (String)
collectionName.evaluate(mutableRecord)
: null;

// Get the bucket, scope, and collection
Bucket bucket = cluster.bucket(bucketS);
bucket.waitUntilReady(Duration.ofSeconds(10));

Scope scope = bucket.scope(scopeS);
collection = scope.collection(collectionS);

// Prepare the content map
Map<String, Object> content = new HashMap<>();

// Add the vector embedding
List<?> vector =
vectorFunction != null
? (List<?>)
vectorFunction.evaluate(mutableRecord)
: null;
if (vector != null) {
content.put("vector", vector);
}

// Add metadata
metadataFunctions.forEach(
(key, evaluator) -> {
Object value = evaluator.evaluate(mutableRecord);
content.put(key, value);
});

// Perform the upsert
MutationResult result =
collection.upsert(
docId, content, UpsertOptions.upsertOptions());

// Logging the result of the upsert operation
log.info("Upsert successful for document ID '{}'", docId);

handle.complete(null); // Completing the future successfully
} catch (Exception e) {
log.error(
"Failed to upsert document with ID '{}'",
record.key(),
e);
handle.completeExceptionally(
e); // Completing the future exceptionally
}
})
.exceptionally(
e -> {
log.error("Exception in upsert operation: ", e);
return null;
});
try {

MutableRecord mutableRecord = recordToMutableRecord(record, true);

// Evaluate the ID using the idFunction
String docId =
idFunction != null ? (String) idFunction.evaluate(mutableRecord) : null;

if (docId == null) {
throw new IllegalArgumentException("docId is null, cannot upsert document");
}

String bucketS =
bucketName != null ? (String) bucketName.evaluate(mutableRecord) : null;
String scopeS =
scopeName != null ? (String) scopeName.evaluate(mutableRecord) : null;
String collectionS =
collectionName != null
? (String) collectionName.evaluate(mutableRecord)
: null;

// Get the bucket, scope, and collection
Bucket bucket = cluster.bucket(bucketS);
bucket.waitUntilReady(Duration.ofSeconds(10));

Scope scope = bucket.scope(scopeS);
collection = scope.collection(collectionS);

// Prepare the content map
Map<String, Object> content = new HashMap<>();

// Add the vector embedding
List<?> vector =
vectorFunction != null
? (List<?>) vectorFunction.evaluate(mutableRecord)
: null;
if (vector != null) {
content.put("vector", vector);
}

// Add metadata
metadataFunctions.forEach(
(key, evaluator) -> {
Object value = evaluator.evaluate(mutableRecord);
content.put(key, value);
});

// Perform the upsert
MutationResult result =
collection.upsert(docId, content, UpsertOptions.upsertOptions());

// Logging the result of the upsert operation
log.info("Upsert successful for document ID '{}'", docId);

handle.complete(null); // Completing the future successfully
} catch (Exception e) {
log.error("Failed to upsert document with ID '{}'", record.key(), e);
handle.completeExceptionally(e); // Completing the future exceptionally
}

return handle;
}
}

private static JstlEvaluator buildEvaluator(
public static JstlEvaluator buildEvaluator(
Map<String, Object> agentConfiguration, String param, Class type) {
String expression = agentConfiguration.getOrDefault(param, "").toString();
if (expression == null || expression.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.testcontainers.containers.wait.strategy.HttpWaitStrategy;
import org.testcontainers.couchbase.BucketDefinition;
Expand All @@ -56,7 +57,7 @@

@Slf4j
@Testcontainers
// @Disabled
@Disabled
class CouchbaseWriterTest {

BucketDefinition bucketDefinition = new BucketDefinition("bucket-name");
Expand Down

0 comments on commit 7886587

Please sign in to comment.