Skip to content

PGVector - Retrieving all documents with metadata filter #29985

Answered by dosubot bot
sunnstix asked this question in Ask Dosu
Discussion options

You must be logged in to vote

To retrieve all documents matching a metadata filter using PGVector without providing an empty string for the query parameter, you can use the similarity_search_with_score method with a filter. This method allows you to specify a filter directly without needing to provide a query string. Here's an example:

def retrieve_documents_with_metadata_filter(pgvector: PGVector, filter: Dict[str, Any]) -> List[Document]:
    """Retrieve documents matching a metadata filter."""
    # Use similarity_search_with_score with a filter and an arbitrary query
    output = pgvector.similarity_search_with_score("arbitrary_query", k=5, filter=filter)
    return [doc for doc, score in output]

# Example usage
p…

Replies: 2 comments 8 replies

Comment options

You must be logged in to vote
4 replies
@sunnstix
Comment options

@dosubot
Comment options

@sunnstix
Comment options

@dosubot
Comment options

Comment options

You must be logged in to vote
4 replies
@dosubot
Comment options

@sunnstix
Comment options

@dosubot
Comment options

Answer selected by sunnstix
@sunnstix
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant