Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust to recent Pinecone query response format change #100

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void cleanup() {
*/
private static void delay() {
try {
int timeout = 40;
int timeout = 30;
Log.info("Waiting " + timeout + " seconds to allow Pinecone time to process deletions");
TimeUnit.SECONDS.sleep(timeout);
} catch (InterruptedException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,19 @@ public List<EmbeddingMatch<TextSegment>> findRelevant(Embedding embedding, int m
QueryRequest request = new QueryRequest(namespace, (long) maxResults, true, true, embedding.vector());
QueryResponse response = vectorOperations.query(request);
return response
.getMatches().stream().map(match -> new EmbeddingMatch<>(
RelevanceScore.fromCosineSimilarity(match.getScore()),
match.getId(),
new Embedding(match.getValues()),
match.getMetadata().get(textFieldName) != null ? new TextSegment(
match.getMetadata().get(textFieldName),
new Metadata(mapWithoutKey(match.getMetadata(), textFieldName))) : null))
.getMatches().stream().map(match -> {
String text = match.getMetadata() != null &&
match.getMetadata().get(textFieldName) != null
? match.getMetadata().get(textFieldName)
: null;
return new EmbeddingMatch<>(
RelevanceScore.fromCosineSimilarity(match.getScore()),
match.getId(),
new Embedding(match.getValues()),
text != null ? new TextSegment(
text,
new Metadata(mapWithoutKey(match.getMetadata(), textFieldName))) : null);
})
.filter(match -> match.score() >= minScore)
.collect(toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,19 @@ public class QueryResponse {

private final List<VectorMatch> matches;

private String metadata;
private String namespace;

@JsonCreator
public QueryResponse(List<VectorMatch> matches, String metadata) {
public QueryResponse(List<VectorMatch> matches, String metadata, String namespace) {
this.matches = matches;
this.metadata = metadata;
this.namespace = namespace;
}

public List<VectorMatch> getMatches() {
return matches;
}

public String getMetadata() {
return metadata;
public String getNamespace() {
return namespace;
}

}
Loading