Installing the library

pip install --upgrade pongo-python

Authentication

Pongo uses secret keys for accessing the API. You can generate, rename, and delete keys on the API Key dashboard.

You can only see API keys once, when they’re generated. After that you can only rename or delete them.

Usage

You can authorize HTTP requests by passing the api key in via headers. The secret key goes in as the “secret” header.

With the client libraries, you can pass the key in once and then all requests are automatically authenticated.

import pongo

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


queries = ["What color are apples?", "Who made the first mobile phone?", "How many hearts do squids have?"]

#pass in the top ~100-200 results from your existing pipeline, passing more results will catch more edge cases but take slightly longer to process
#You can use objects like the first row, or raw text like the other two
lists_of_results = [
    # Apples results
    [
        {'text': 'Oranges are normally orange, unlike apples', 'metadata': {'source': 'Fruit documentation'}},
        {'text': 'Grapes can be purple or green', 'metadata': {'source': 'Fruit documentation'}},
        {'text': 'Apples can be green or red.', 'metadata': {'source': 'Fruit documentation'}},
        {'text': "If an apple is brown, it's best not to eat it.", 'metadata': {'source': 'Fruit documentation'}}
    ],
    # Mobile phone results
    [
        'Apple released the first iPhone on June 29, 2007',
        'The telephone was invented by Alexander Graham Bell in 1876.',
        'The first long-distance telephone call was made in August 1876, between Brantford and Paris, Ontario',
        'The newest iPhone models are the iPhone 15, it was released on September 22, 2023',
        'The first handheld mobile phone was the Motorola DynaTAC 8000X',
        'Martin Cooper, an engineer at Motorola, is credited with inventing the first handheld cellular mobile phone and making the first mobile phone call'
    ],
    # Squids results
    [
        'Octopuses have three hearts.',
        "A squid's systemic (main) heart has three chambers.",
        'The creature with the most hearts is the earthworm, with 10.',
        'Squids have three hearts- one systemic (main) heart and two branchial hearts'
    ]
]

for i in range(len(queries)):
    #observe=True adds automatic evaluation to queries, you'll get a regular email report and can view / download queries via the dashboard.
    filtered_result = pongo_client.filter(docs=lists_of_results[i], query=queries[i], num_results=5, observe=True, log_metadata={'source': 'Pongo Tutorial'})
    filtered_docs = filtered_result.json()

    print(f'Top answer to: {queries[i]}: {filtered_docs[0]["text"]}\n\n')