Similarity API in cURL

This page will show you examples of how to work with the Similarity API from cURL, but you can also find more explanations and examples in other languages from the Similarity API page.

Prerequisites

You need to create a deployment from the deployment view. The deployment view will show you the information you need to use the Deployment API:

  • The name of the input feature used for similarity

  • The URL and deployment token to use for your requests

  • The status of the deployment. Make sure it is enabled, or queries will be denied

Examples

Find similar texts in Python

Text data can be any kind of text written in natural languages, i.e., the way humans read and write. Check the Find similar Google questions tutorial to see how to deploy a model for this task.

You use the -F flag to specify both the name of the text Input feature to search and the text string for which you want to find similar examples.

Likewise, you can use -F to specify how many of the closest examples you want the API to return by specifying the limit option. If you don’t specify it, the 5 most similar examples will be returned by default.

curl -X POST -F "question=Who is the most famous?" -F "limit=2" -u "9dba2730-0488-<...>9a0d-20e4a8ed9681:" https://api<...>deployment/similarity/987eec28-4f87<...>beb17282c317

> {"deploymentId":"987eec28-4f87<...>beb17282c317","similarities":[{"distance":0.146,"index":239423,"features":{"answer":"PewDiePie","question":"who is the most famous person on youtube","index":239423}},{"distance":0.156,"index":269957,"features":{"answer":"n/a","question":"who is the most famous person from maine","index":269957}}]}

Find similar images in Python

You can also send an image file and retrieve images from your dataset that share visual similarities. You can pass the name of an image file using the @ symbol in the cURL command.

curl -X POST -F "image=@picture_001.jpg" -u "9dba2730-0488-<...>9a0d-20e4a8ed9681:" https://api<...>deployment/similarity/987eec28-4f87<...>beb17282c317

> {"deploymentId":"987eec28-4f87<...>beb17282c317","similarities":[{"distance":0.529,"index":22928,"features":{"image":"/9j/4AAQS..."}}]}

The string returned as the image feature is the raw image file data, encoded as text using base 64.

Was this page helpful?
YesNo