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

pinecone[patch]: Fix document ID not getting set when returned from PineconeStore #6539

Merged
merged 4 commits into from
Aug 16, 2024

Conversation

nick-w-nick
Copy link
Contributor

When querying for documents using the PineconeStore via the various search methods, the documents getting returned from Pinecone currently have their id property set to undefined.

This is because id is omitted when the result is converted to a document prior to being returned, as shown below for each query method respectively:

similaritySearchVectorWithScore

if (res.score) {
result.push([new Document({ metadata, pageContent }), res.score]);
}

maxMarginalRelevanceSearch

if (res.score) {
finalResult.push(new Document({ metadata, pageContent }));
}

This PR adds a new private method named _formatMatches that accepts an array of matches (ScoredPineconeRecord) from the QueryResponse interface. This method performs the same logic that was duplicated across the query methods, just with some added deconstruction safety rails as well as the addition of the id property.

Result from similaritySearchWithScore before this change (same for similaritySearchVectorWithScore):

[
  [
    Document {
      pageContent: 'document text',
      metadata: [Object],
      id: undefined
    },
    0.81118
  ]
]

Result from similaritySearchWithScore after this change (same for similaritySearchVectorWithScore):

[
  [
    Document {
      pageContent: 'document text',
      metadata: [Object],
      id: '91522887-3be3-4937-9ea7-eb235b991a4c'
    },
    0.81118
  ]
]

Result from similaritySearch before this change (same as maxMarginalRelevanceSearch):

[
  [
    Document {
      pageContent: 'document text',
      metadata: [Object],
      id: undefined
    }
  ]
]

Result from similaritySearch after this change (same as maxMarginalRelevanceSearch):

[
  [
    Document {
      pageContent: 'document text',
      metadata: [Object],
      id: '91522887-3be3-4937-9ea7-eb235b991a4c'
    }
  ]
]

@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Aug 15, 2024
Copy link

vercel bot commented Aug 15, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
langchainjs-docs ✅ Ready (Inspect) Visit Preview Aug 16, 2024 9:27am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
langchainjs-api-refs ⬜️ Ignored (Inspect) Aug 16, 2024 9:27am

@dosubot dosubot bot added the auto:improvement Medium size change to existing code to handle new use-cases label Aug 15, 2024
@nick-w-nick nick-w-nick changed the title Fix document ID not getting set when returned from PineconeStore community[patch]: Fix document ID not getting set when returned from PineconeStore Aug 15, 2024
Copy link
Collaborator

@bracesproul bracesproul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for pushing this up, well needed update! Could you also push up a commit adding a test for this? Thank you!

@bracesproul bracesproul changed the title community[patch]: Fix document ID not getting set when returned from PineconeStore pinecone[patch]: Fix document ID not getting set when returned from PineconeStore Aug 15, 2024
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Aug 16, 2024
@jacoblee93 jacoblee93 merged commit f49f4e0 into langchain-ai:main Aug 16, 2024
27 checks passed
@jacoblee93
Copy link
Collaborator

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto:improvement Medium size change to existing code to handle new use-cases size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants