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

community: Add support for negative embeddings in PGVector #19310

Closed
wants to merge 5 commits into from

Conversation

White-RaBot
Copy link

@White-RaBot White-RaBot commented Mar 20, 2024

Description: This commit introduces the capability to pass negative embeddings as a list of strings to the similarity_search_with_score_by_vector method in the PGVector vectorstore. Negative embeddings allow for refining search results by excluding certain concepts or themes.

Key changes:

  • Update similarity_search_with_score_by_vector to accept a negative_embeddings parameter as a list of strings.
  • Modify __query_collection to convert negative strings to embeddings and incorporate them into the search query.
  • Add a filter condition in __query_collection to exclude results based on their similarity to the negative embeddings.
  • Handle cases where the negative embeddings are missing or not in the expected format gracefully.

This feature enables users to have more control over their search results by specifying negative concepts to exclude. The negative embeddings are converted to vector embeddings using the provided embedding function and used to filter out unwanted results based on a configurable threshold.

Example usage:

negative_concepts = ["cats", "dogs"]
results = vectorstore.similarity_search_with_score_by_vector(
   embedding=query_embedding,
   k=10,
   negative_embeddings=negative_concepts
)

Dependencies: No additional dependencies are required for this change.

Twitter Handle: @GentJayson

Copy link

vercel bot commented Mar 20, 2024

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

Name Status Preview Comments Updated (UTC)
langchain ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 18, 2024 3:36am

@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. Ɑ: vector store Related to vector store module 🔌: postgres Related to postgres integrations 🤖:improvement Medium size change to existing code to handle new use-cases labels Mar 20, 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 Jun 15, 2024
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Jun 15, 2024
@isahers1
Copy link
Collaborator

@White-RaBot Please fix errors in pgvector.py, I believe lint is yelling because there are type errors

@ccurme ccurme added the community Related to langchain-community label Jun 18, 2024
@efriis
Copy link
Member

efriis commented Aug 30, 2024

closing due to no response - would also recommend doing this against the integration package in langchain-ai/langchain-postgres now instead of on the deprecated community integration!

@efriis efriis closed this Aug 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community Related to langchain-community 🤖:improvement Medium size change to existing code to handle new use-cases 🔌: postgres Related to postgres integrations size:M This PR changes 30-99 lines, ignoring generated files. Ɑ: vector store Related to vector store module
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

5 participants