Search

Note: The Search API currently is only available for images.

A common case for using Clarifai is to get the concepts predicted in an image and then use those concepts to power search.

The Search API allows you to send images (url or bytes) to the service and have them indexed by 'general' model concepts and their visual representations. Once indexed, you can search for images by concept or by image.

Image illustrating how to search by images using Clarifai's concepts

Add Images to Search Index

To get started with search, you must first add images to the search index. You can add one or more images to the index at a time. You can supply an image either with a publicly accessible URL or by directly sending image bytes. You can send up to 128 images in one API call.

js
python
java
csharp
objective-c
php
cURL
app.inputs.create([
{url: "https://samples.clarifai.com/metro-north.jpg"},
{url: "https://samples.clarifai.com/wedding.jpg"},
{base64: "G7p3m95uAl..."}
]).then(
‚Äč
function(response) {
// do something with response
},
function(err) {
// there was an error
}
);
Response JSON
{
"status": {
"code": 10000,
"description": "Ok"
},
"inputs": [
{
"id": "edc70c917475499abdc7151f41d6cf3e",
"created_at": "2016-11-22T17:06:02Z",
"data": {
"image": {
"url": "https://samples.clarifai.com/metro-north.jpg"
}
},
"status": {
"code": 30001,
"description": "Download pending"
}
},
{
"id": "f96ca3bbf02041c59addcc13e3468b7d",
"created_at": "2016-11-22T17:06:02Z",
"data": {
"image": {
"url": "https://samples.clarifai.com/wedding.jpg"
}
},
"status": {
"code": 30001,
"description": "Download pending"
}
}
]
}

Search By Concept

Once your images are indexed, you can search for them by concept.

js
python
java
csharp
objective-c
php
cURL
app.inputs.search({ concept: {name: 'people'} }).then(
function(response) {
// do something with response
},
function(err) {
// there was an error
}
);
Response JSON
{
"status": {
"code": 10000,
"description": "Ok"
},
"id":"d275a3c0f3e748378617d6ba9bd0f8d4",
"hits": [
{
"score": 0.98155165,
"input": {
"id": "f96ca3bbf02041c59addcc13e3468b7d",
"created_at": "2016-11-22T17:06:02Z",
"data": {
"image": {
"url": "https://samples.clarifai.com/wedding.jpg"
}
},
"status": {
"code": 30000,
"description": "Download complete"
}
}
}
]
}

Search By Image

You can also search for images using another image. In this case, you provide an image (url or bytes) and the results will return all the images in your search index that are visually similar to the one provided.

js
python
java
csharp
objective-c
php
cURL
app.inputs.search({ input: {url: 'https://samples.clarifai.com/puppy.jpg'} }).then(
function(response) {
// do something with response
},
function(err) {
// there was an error
}
);
Response JSON
{
"status": {
"code": 10000,
"description": "Ok"
},
"id": "bd94239099d44d4686f38ca753495e22",
"hits": [
{
"score": 0.9999997,
"input": {
"id": "edc70c917475499abdc7151f41d6cf3e",
"created_at": "2016-11-22T17:06:02Z",
"data": {
"image": {
"url": "https://samples.clarifai.com/metro-north.jpg"
}
},
"status": {
"code": 30000,
"description": "Download complete"
}
}
},
{
"score": 0.3915897,
"input": {
"id": "f96ca3bbf02041c59addcc13e3468b7d",
"created_at": "2016-11-22T17:06:02Z",
"data": {
"image": {
"url": "https://samples.clarifai.com/wedding.jpg"
}
},
"status": {
"code": 30000,
"description": "Download complete"
}
}
}
]
}