Skip to content

Commit

Permalink
Merge pull request #100 from jmartisk/pinecone-format
Browse files Browse the repository at this point in the history
Adjust to recent Pinecone query response format change
  • Loading branch information
geoand authored Dec 7, 2023
2 parents dc451f3 + a371197 commit aab4e44
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
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;
}

}

0 comments on commit aab4e44

Please sign in to comment.