This guide will help you improve RAG accuracy by as much as 35% with only one line of code.

1. Create an Account

Go to to create an account- be sure to save the API key generated during onboarding or get one from the API keys page

2. Install the Pongo Client

pip install --upgrade pongo-python

3. Semantic Filter with Pongo

Run your pipeline and pass the top 50-100 results to Pongo along with your query, then you’ll get the top-k back in order of relevance for use in your application!

import pongo

#Replace the key with your actual API key
pongo_client = pongo.PongoClient(PONGO_SECRET_KEY)

query = "What color are apples?"

#pass in the top ~50-100 results from your existing pipeline, passing more results will catch more edge cases but take longer to process
results_to_filter = [{"id": 1, "text": "Oranges are orange", "metadata": {}}, 
    {"id": 2, "text": "Apples can be red or green", "metadata": {}}, 
    {"id": 3, "text": "Grapes can be purple or green", "metadata": {}}, 
    {"id": 4, "text": "Banannas are yellow", "metadata": {}}]

pongo_result = pongo_client.filter(docs=results_to_filter, query=query, num_results=10, public_metadata_field="metadata", key_field="id", text_field='text')

#List of the 10 most relevant documents to the query
filtered_docs = pongo_result.json()