POST
/
filter
import { PongoClient } from 'pongo-typescript'
// Install with npm i pongo-typescript

// Replace the key with your actual API key
const pongoClient = new PongoClient("${private_key || 'loading key...'}")

const 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
const listsOfResults = [
    [
        {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'}}
    ], // Apples 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'
    ], // Mobile phone 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'
    ] // squids results
]

for (let i = 0; i < queries.length; i++) {
    // observe=true adds automatic evaluation to queries, you'll get a regular email report and can view / download queries via the dashboard.
    pongoClient.filter({
        docs: listsOfResults[i],
        query: queries[i],
        numResults: 5,
        observe: true,
        logMetadata: {source: 'Pongo Tutorial'}
    }).then(filteredResult => {
        const filteredDocs = filteredResult.data
        console.log(`Top answer to: ${queries[i]}: ${filteredDocs[0].text}\n\n`)
    })
}
[
  {
    "id": "doc-id",
    "text": "Document data",
    "metadata": {},
    "score": 0.9482
  }
]
If you want to observe your pipeline wihtout changing behavior, check out the /observe endpoint

Authorizations

secret
string
header
required

Body

application/json
query
string

Query that was initally passed into your pipeline

docs
object
observe
boolean
default:false

Wether or not to run the observability pipeline on this query

num_results
integer
default:10

Total number of results returned by the filter

text_field
string
default:text

Field to be filtered on, default is "text"

public_metadata_field
string
default:metadata

Name of the object key to the metadata field of each document being passed in. Default is "metadata"

key_field
string
default:id

Name of the object key to be used as the ID field for each document passed into the scoring system. Default is "id"

vec_sample_size
integer
default:25

Number of vector results to be passed to the last step of our scoring system

plaintext_sample_size
integer
default:5

Number of plain text results to be passed to the last step of our at the end of our scoring system

Response

200 - application/json
Successful response
id
string

Unique identifier for the document.

Example:

"doc-id"

text
string

The text content of the document.

Example:

"Document data"

metadata
object

Metadata associated with the document.

score
number

Relevance score of the document.

Example:

0.9482