Rank
Search your data based on concepts or visual similarity
Rank Order your search results with the intuitive insights of AI. Your model can identify concepts in your data and rank your search results by how confident it is that a given concept is present. You can even rank search results by how similar one input is to another input or region of the input model detected. The search results will return the input but also the annotation which includes the region.

Search By Concepts

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

By clarifai/main App Concepts

When you add an input, it automatically gets predictions from the models in your base workflow which are typically models from the clarifai/main app such as the general model. You can search by those predictions.
Java
NodeJS
Python
cURL
Javascript (REST)
1
import com.clarifai.grpc.api.*;
2
import com.clarifai.grpc.api.status.*;
3
4
// Insert here the initialization code as outlined on this page:
5
// https://docs.clarifai.com/api-guide/api-overview
6
7
MultiSearchResponse postAnnotationsSearchesResponse = stub.postAnnotationsSearches(
8
PostAnnotationsSearchesRequest.newBuilder().addSearches(
9
Search.newBuilder().setQuery(
10
Query.newBuilder().addRanks(
11
Rank.newBuilder().setAnnotation(
12
Annotation.newBuilder().setData(
13
Data.newBuilder().addConcepts( // You can search by multiple concepts.
14
Concept.newBuilder()
15
.setId("people") // You could search by concept Name as well.
16
.setValue(1f) // Value of 0 will search for images that don't have the concept.
17
)
18
)
19
)
20
)
21
)
22
)
23
.build()
24
);
25
26
if (postAnnotationsSearchesResponse.getStatus().getCode() != StatusCode.SUCCESS) {
27
throw new RuntimeException("Post annotations searches failed, status: " + postAnnotationsSearchesResponse.getStatus());
28
}
29
30
System.out.println("Found inputs " + postAnnotationsSearchesResponse.getHitsCount() + ":");
31
for (Hit hit : postAnnotationsSearchesResponse.getHitsList()) {
32
System.out.printf("\tScore %.2f for annotation % of input %s\n", hit.getScore(), hit.getAnnotation().getId(), hit.getInput().getId())
33
}
Copied!
1
// Insert here the initialization code as outlined on this page:
2
// https://docs.clarifai.com/api-guide/api-overview
3
4
stub.PostAnnotationsSearches(
5
{
6
searches: [
7
{
8
query: {
9
ranks: [
10
{
11
annotation: {
12
data: {
13
concepts: [ // You can search by multiple concepts.
14
{
15
id: "people", // You could search by concept Name as well.
16
value: 1 // Value of 0 will search for images that don't have the concept
17
}
18
]
19
}
20
}
21
}
22
]
23
}
24
}
25
]
26
},
27
metadata,
28
(err, response) => {
29
if (err) {
30
throw new Error(err);
31
}
32
33
if (response.status.code !== 10000) {
34
throw new Error("Post annotations searches failed, status: " + response.status.description);
35
}
36
37
console.log("Search result:");
38
for (const hit of response.hits) {
39
console.log("\tScore " + hit.score + " for annotation: " + hit.annotation.id + " of input: ", hit.input.id);
40
}
41
}
42
);
Copied!
1
from clarifai_grpc.grpc.api import service_pb2, resources_pb2
2
from clarifai_grpc.grpc.api.status import status_code_pb2
3
4
# Insert here the initialization code as outlined on this page:
5
# https://docs.clarifai.com/api-guide/api-overview
6
7
post_annotations_searches_response = stub.PostAnnotationsSearches(
8
service_pb2.PostAnnotationsSearchesRequest(
9
searches = [
10
resources_pb2.Search(
11
query=resources_pb2.Query(
12
ranks=[
13
resources_pb2.Rank(
14
annotation=resources_pb2.Annotation(
15
data=resources_pb2.Data(
16
concepts=[ # You can search by multiple concepts.
17
resources_pb2.Concept(
18
id="people", # You could search by concept Name as well.
19
value=1 # Value of 0 will search for images that don't have the concept.
20
)
21
]
22
)
23
)
24
)
25
]
26
)
27
)
28
]
29
),
30
metadata=metadata
31
)
32
33
if post_annotations_searches_response.status.code != status_code_pb2.SUCCESS:
34
print("There was an error with your request!")
35
print("\tCode: {}".format(post_annotations_searches_response.outputs[0].status.code))
36
print("\tDescription: {}".format(post_annotations_searches_response.outputs[0].status.description))
37
print("\tDetails: {}".format(post_annotations_searches_response.outputs[0].status.details))
38
raise Exception("Post searches failed, status: " + post_annotations_searches_response.status.description)
39
40
print("Search result:")
41
for hit in post_annotations_searches_response.hits:
42
print("\tScore %.2f for annotation: %s off input: %s" % (hit.score, hit.annotation.id, hit.input.id))
Copied!
1
#
2
# Value of 0 will search for images that don't have the concept.
3
#
4
# Instead of "id" you can search by "name" as well.
5
6
curl -X POST \
7
-H "Authorization: Key YOUR_API_KEY" \
8
-H "Content-Type: application/json" \
9
-d '
10
{
11
"searches": [
12
{
13
"query": {
14
"ranks": [
15
{
16
"annotation": {
17
"data": {
18
"concepts": [
19
{
20
"id":"people",
21
"value": 1
22
}
23
]
24
}
25
}
26
}
27
]
28
}
29
}
30
]
31
}'\
32
https://api.clarifai.com/v2/annnotations/searches
Copied!
1
const raw = JSON.stringify({
2
"user_app_id": {
3
"user_id": "{YOUR_USER_ID}",
4
"app_id": "{YOUR_APP_ID}"
5
},
6
"searches": [
7
{
8
"query": {
9
"ranks": [
10
{
11
"annotation": {
12
"data": {
13
"concepts": [
14
{
15
"id":"people",
16
"value": 1
17
}
18
]
19
}
20
}
21
}
22
]
23
}
24
}
25
]
26
});
27
28
const requestOptions = {
29
method: 'POST',
30
headers: {
31
'Accept': 'application/json',
32
'Authorization': 'Key {YOUR_PERSONAL_TOKEN}'
33
},
34
body: raw
35
};
36
37
fetch(`https://api.clarifai.com/v2/annnotations/searches`, requestOptions)
38
.then(response => response.text())
39
.then(result => console.log(result))
40
.catch(error => console.log('error', error));
Copied!

By Custom Concepts

After you have added inputs, annotation the inputs, and try a custom model, you can search by those concepts.
Java
NodeJS
Python
cURL
Javascript (REST)
1
import com.clarifai.grpc.api.*;
2
import com.clarifai.grpc.api.status.*;
3
4
// Insert here the initialization code as outlined on this page:
5
// https://docs.clarifai.com/api-guide/api-overview
6
7
MultiSearchResponse postAnnotationsSearchesResponse = stub.postAnnotationsSearches(
8
PostAnnotationsSearchesRequest.newBuilder().addSearches(
9
Search.newBuilder().setQuery(
10
Query.newBuilder().addRanks(
11
Rank.newBuilder().setAnnotation(
12
Annotation.newBuilder().setData(
13
Data.newBuilder().addConcepts( // You can search by multiple concepts.
14
Concept.newBuilder()
15
.setId("people") // You could search by concept Name as well.
16
.setValue(1f) // Value of 0 will search for images that don't have the concept.
17
)
18
)
19
)
20
)
21
)
22
)
23
.build()
24
);
25
26
if (postAnnotationsSearchesResponse.getStatus().getCode() != StatusCode.SUCCESS) {
27
throw new RuntimeException("Post annotations searches failed, status: " + postAnnotationsSearchesResponse.getStatus());
28
}
29
30
System.out.println("Found inputs " + postAnnotationsSearchesResponse.getHitsCount() + ":");
31
for (Hit hit : postAnnotationsSearchesResponse.getHitsList()) {
32
System.out.printf("\tScore %.2f for annotation % of input %s\n", hit.getScore(), hit.getAnnotation().getId(), hit.getInput().getId())
33
}
Copied!
1
// Insert here the initialization code as outlined on this page:
2
// https://docs.clarifai.com/api-guide/api-overview
3
4
stub.PostAnnotationsSearches(
5
{
6
searches: [
7
{
8
query: {
9
ranks: [
10
{
11
annotation: {
12
data: {
13
concepts: [ // You can search by multiple concepts.
14
{
15
id: "people", // You could search by concept Name as well.
16
value: 1 // Value of 0 will search for images that don't have the concept
17
}
18
]
19
}
20
}
21
}
22
]
23
}
24
}
25
]
26
},
27
metadata,
28
(err, response) => {
29
if (err) {
30
throw new Error(err);
31
}
32
33
if (response.status.code !== 10000) {
34
throw new Error("Post annotations searches failed, status: " + response.status.description);
35
}
36
37
console.log("Search result:");
38
for (const hit of response.hits) {
39
console.log("\tScore " + hit.score + " for annotation: " + hit.annotation.id + " of input: ", hit.input.id);
40
}
41
}
42
);
Copied!
1
from clarifai_grpc.grpc.api import service_pb2, resources_pb2
2
from clarifai_grpc.grpc.api.status import status_code_pb2
3
4
# Insert here the initialization code as outlined on this page:
5
# https://docs.clarifai.com/api-guide/api-overview
6
7
post_annotations_searches_response = stub.PostAnnotationsSearches(
8
service_pb2.PostAnnotationsSearchesRequest(
9
searches = [
10
resources_pb2.Search(
11
query=resources_pb2.Query(
12
ranks=[
13
resources_pb2.Rank(
14
annotation=resources_pb2.Annotation(
15
data=resources_pb2.Data(
16
concepts=[ # You can search by multiple concepts.
17
resources_pb2.Concept(
18
id="people", # You could search by concept Name as well.
19
value=1 # Value of 0 will search for images that don't have the concept.
20
)
21
]
22
)
23
)
24
)
25
]
26
)
27
)
28
]
29
),
30
metadata=metadata
31
)
32
33
if post_annotations_searches_response.status.code != status_code_pb2.SUCCESS:
34
print("There was an error with your request!")
35
print("\tCode: {}".format(post_annotations_searches_response.outputs[0].status.code))
36
print("\tDescription: {}".format(post_annotations_searches_response.outputs[0].status.description))
37
print("\tDetails: {}".format(post_annotations_searches_response.outputs[0].status.details))
38
raise Exception("Post searches failed, status: " + post_annotations_searches_response.status.description)
39
40
print("Search result:")
41
for hit in post_annotations_searches_response.hits:
42
print("\tScore %.2f for annotation: %s off input: %s" % (hit.score, hit.annotation.id, hit.input.id))
Copied!
1
#
2
# Value of 0 will search for images that don't have the concept.
3
#
4
# Instead of "id" you can search by "name" as well.
5
6
curl -X POST \
7
-H "Authorization: Key YOUR_API_KEY" \
8
-H "Content-Type: application/json" \
9
-d '
10
{
11
"searches": [
12
{
13
"query": {
14
"ranks": [
15
{
16
"annotation": {
17
"data": {
18
"concepts": [
19
{
20
"id":"people",
21
"value": 1
22
}
23
]
24
}
25
}
26
}
27
]
28
}
29
}
30
]
31
}'\
32
https://api.clarifai.com/v2/annnotations/searches
Copied!
1
const raw = JSON.stringify({
2
"user_app_id": {
3
"user_id": "{YOUR_USER_ID}",
4
"app_id": "{YOUR_APP_ID}"
5
},
6
"searches": [
7
{
8
"query": {
9
"ranks": [
10
{
11
"annotation": {
12
"data": {
13
"concepts": [
14
{
15
"id":"people",
16
"value": 1
17
}
18
]
19
}
20
}
21
}
22
]
23
}
24
}
25
]
26
});
27
28
const requestOptions = {
29
method: 'POST',
30
headers: {
31
'Accept': 'application/json',
32
'Authorization': 'Key {YOUR_PERSONAL_TOKEN}'
33
},
34
body: raw
35
};
36
37
fetch(`https://api.clarifai.com/v2/annnotations/searches`, requestOptions)
38
.then(response => response.text())
39
.then(result => console.log(result))
40
.catch(error => console.log('error', error));
Copied!

By clarifai/main and custom concepts

You can combine a search to find inputs that have concepts you have supplied as well as predictions from your model.
Java
NodeJS
Python
cURL
Javascript (REST)
1
import com.clarifai.grpc.api.*;
2
import com.clarifai.grpc.api.status.*;
3
4
// Insert here the initialization code as outlined on this page:
5
// https://docs.clarifai.com/api-guide/api-overview
6
7
// Here we search for images which we labeled with "cat" and for which the General prediction model does not find
8
// a "dog" concept.
9
MultiSearchResponse postAnnotationsSearchesResponse = stub.postAnnotationsSearches(
10
PostAnnotationsSearchesRequest.newBuilder().addSearches(
11
Search.newBuilder().setQuery(
12
Query.newBuilder().addRanks(
13
Rank.newBuilder().setAnnotation(
14
Annotation.newBuilder().setData(
15
Data.newBuilder().addConcepts( // You can search by multiple concepts.
16
Concept.newBuilder()
17
.setId("cat") // You could search by concept Name as well.
18
.setValue(1f) // Value of 0 will search for images that don't have the concept.
19
)
20
)
21
)
22
)
23
.addRanks(
24
Rank.newBuilder().setAnnotation(
25
Annotation.newBuilder().setData(
26
Data.newBuilder().addConcepts( // You can search by multiple concepts.
27
Concept.newBuilder()
28
.setId("dog") // You could search by concept Name as well.
29
.setValue(0f) // Value of 0 will search for images that don't have the concept.
30
)
31
)
32
)
33
)
34
)
35
)
36
.build()
37
);
38
39
if (postAnnotationsSearchesResponse.getStatus().getCode() != StatusCode.SUCCESS) {
40
throw new RuntimeException("Post annotations searches failed, status: " + postAnnotationsSearchesResponse.getStatus());
41
}
42
43
System.out.println("Found inputs " + postAnnotationsSearchesResponse.getHitsCount() + ":");
44
for (Hit hit : postAnnotationsSearchesResponse.getHitsList()) {
45
System.out.printf("\tScore %.2f for annotation % of input %s\n", hit.getScore(), hit.getAnnotation().getId(), hit.getInput().getId())
46
}
Copied!
1
// Insert here the initialization code as outlined on this page:
2
// https://docs.clarifai.com/api-guide/api-overview
3
4
// Here we search for images which we labeled with "cat" and for which the General prediction model does not find
5
// a "dog" concept.
6
7
stub.PostAnnotationsSearches(
8
{
9
searches: [
10
{
11
query: {
12
ranks: [
13
{
14
annotation: {
15
data: {
16
concepts: [ // You can search by multiple concepts.
17
{
18
id: "cat", // You could search by concept Name as well.
19
value: 1 // Value of 0 will search for images that don't have the concept
20
}
21
]
22
}
23
}
24
}, {
25
annotation: {
26
data: {
27
concepts: [ // You can search by multiple concepts.
28
{
29
id: "dog", // You could search by concept Name as well.
30
value: 0 // Value of 0 will search for images that don't have the concept
31
}
32
]
33
}
34
}
35
}
36
]
37
}
38
}
39
]
40
},
41
metadata,
42
(err, response) => {
43
if (err) {
44
throw new Error(err);
45
}
46
47
if (response.status.code !== 10000) {
48
throw new Error("Post annotations searches failed, status: " + response.status.description);
49
}
50
51
console.log("Search result:");
52
for (const hit of response.hits) {
53
console.log("\tScore " + hit.score + " for annotation: " + hit.annotation.id + " of input: ", hit.input.id);
54
}
55
}
56
);
Copied!
1
from clarifai_grpc.grpc.api import service_pb2, resources_pb2
2
from clarifai_grpc.grpc.api.status import status_code_pb2
3
4
# Insert here the initialization code as outlined on this page:
5
# https://docs.clarifai.com/api-guide/api-overview
6
7
# Here we search for images which we labeled with "cat" and for which the General prediction model does not find
8
# a "dog" concept.
9
10
post_annotations_searches_response = stub.PostAnnotationsSearches(
11
service_pb2.PostAnnotationsSearchesRequest(
12
searches = [
13
resources_pb2.Search(
14
query=resources_pb2.Query(
15
ranks=[
16
resources_pb2.Rank(
17
annotation=resources_pb2.Annotation(
18
data=resources_pb2.Data(
19
concepts=[ # You can search by multiple concepts.
20
resources_pb2.Concept(
21
id="cat", # You could search by concept Name as well.
22
value=1 # Value of 0 will search for images that don't have the concept.
23
)
24
]
25
)
26
)
27
),
28
resources_pb2.Rank(
29
annotation=resources_pb2.Annotation(
30
data=resources_pb2.Data(
31
concepts=[ # You can search by multiple concepts.
32
resources_pb2.Concept(
33
id="dog", # You could search by concept Name as well.
34
value=0 # Value of 0 will search for images that don't have the concept.
35
)
36
]
37
)
38
)
39
)
40
]
41
)
42
)
43
]
44
),
45
metadata=metadata
46
)
47
48
if post_annotations_searches_response.status.code != status_code_pb2.SUCCESS:
49
print("There was an error with your request!")
50
print("\tCode: {}".format(post_annotations_searches_response.outputs[0].status.code))
51
print("\tDescription: {}".format(post_annotations_searches_response.outputs[0].status.description))
52
print("\tDetails: {}".format(post_annotations_searches_response.outputs[0].status.details))
53
raise Exception("Post searches failed, status: " + post_annotations_searches_response.status.description)
54
55
print("Search result:")
56
for hit in post_annotations_searches_response.hits:
57
print("\tScore %.2f for annotation: %s off input: %s" % (hit.score, hit.annotation.id, hit.input.id))
Copied!
1
#
2
# Value of 0 will search for images that don't have the concept.
3
#
4
# Instead of "id" you can search by "name" as well.
5
6
# Here we search for images which we labeled with "cat" and for which the General prediction model does not find
7
# a "dog" concept.
8
9
curl -X POST \
10
-H "Authorization: Key YOUR_API_KEY" \
11
-H "Content-Type: application/json" \
12
-d '
13
{
14
"searches": [
15
{
16
"query": {
17
"ranks": [
18
{
19
"annotation": {
20
"data": {
21
"concepts": [
22
{
23
"id":"cat",
24
"value": 1
25
}
26
]
27
}
28
}
29
}, {
30
"annotation": {
31
"data": {
32
"concepts": [
33
{
34
"id":"dog",
35
"value": 0
36
}
37
]
38
}
39
}
40
}
41
]
42
}
43
}
44
]
45
}'\
46
https://api.clarifai.com/v2/annnotations/searches
Copied!
1
const raw = JSON.stringify({
2
"user_app_id": {
3
"user_id": "{YOUR_USER_ID}",
4
"app_id": "{YOUR_APP_ID}"
5
},
6
"searches": [
7
{
8
"query": {
9
"ranks": [
10
{
11
"annotation": {
12
"data": {
13
"concepts": [
14
{
15
"id":"cat",
16
"value": 1
17
}
18
]
19
}
20
}
21
}, {
22
"annotation": {
23
"data": {
24
"concepts": [
25
{
26
"id":"dog",
27
"value": 0
28
}
29
]
30
}
31
}
32
}
33
]
34
}
35
}
36
]
37
});
38
39
const requestOptions = {
40
method: 'POST',
41
headers: {
42
'Accept': 'application/json',
43
'Authorization': 'Key {YOUR_PERSONAL_TOKEN}'
44
},
45
body: raw
46
};
47
48
fetch(`https://api.clarifai.com/v2/annnotations/searches`, requestOptions)
49
.then(response => response.text())
50
.then(result => console.log(result))
51
.catch(error => console.log('error', error));
Copied!

By concept in another language

Concepts that have a translation into another language can be searched for in that language, even without having the default language for your app being in that language. This uses Clarifai's knowledge graph to lookup the translation and then perform the search. For example, if you app is in english and you want to search for "dog" in Japanese, then you could search with language="ja" and name="犬".
Java
NodeJS
Python
cURL
Javascript (REST)
1
import com.clarifai.grpc.api.*;
2
import com.clarifai.grpc.api.status.*;
3
4
// Insert here the initialization code as outlined on this page:
5
// https://docs.clarifai.com/api-guide/api-overview
6
7
MultiSearchResponse postAnnotationsSearchesResponse = stub.postAnnotationsSearches(
8
PostAnnotationsSearchesRequest.newBuilder().addSearches(
9
Search.newBuilder().setQuery(
10
Query.newBuilder().addRanks(
11
Rank.newBuilder().setAnnotation(
12
Annotation.newBuilder().setData(
13
Data.newBuilder().addConcepts( // You can search by multiple concepts.
14
Concept.newBuilder()
15
.setName("犬") // You could search by concept ID as well.
16
.setLanguage("ja") // japanese
17
.setValue(1f) // Value of 0 will search for images that don't have the concept.
18
)
19
)
20
)
21
)
22
)
23
)
24
.build()
25
);
26
27
if (postAnnotationsSearchesResponse.getStatus().getCode() != StatusCode.SUCCESS) {
28
throw new RuntimeException("Post annotations searches failed, status: " + postAnnotationsSearchesResponse.getStatus());
29
}
30
31
System.out.println("Found inputs " + postAnnotationsSearchesResponse.getHitsCount() + ":");
32
for (Hit hit : postAnnotationsSearchesResponse.getHitsList()) {
33
System.out.printf("\tScore %.2f for annotation % of input %s\n", hit.getScore(), hit.getAnnotation().getId(), hit.getInput().getId())
34
}
Copied!
1
// Insert here the initialization code as outlined on this page:
2
// https://docs.clarifai.com/api-guide/api-overview
3
4
stub.PostAnnotationsSearches(
5
{
6
searches: [
7
{
8
query: {
9
ranks: [
10
{
11
annotation: {
12
data: {
13
concepts: [ // You can search by multiple concepts.
14
{
15
name: "犬", // You could search by concept Id as well.
16
language: "ja", // japanese
17
value: 1 // Value of 0 will search for images that don't have the concept
18
}
19
]
20
}
21
}
22
}
23
]
24
}
25
}
26
]
27
},
28
metadata,
29
(err, response) => {
30
if (err) {
31
throw new Error(err);
32
}
33
34
if (response.status.code !== 10000) {
35
throw new Error("Post annotations searches failed, status: " + response.status.description);
36
}
37
38
console.log("Search result:");
39
for (const hit of response.hits) {
40
console.log("\tScore " + hit.score + " for annotation: " + hit.annotation.id + " of input: ", hit.input.id);
41
}
42
}
43
);
Copied!
1
from clarifai_grpc.grpc.api import service_pb2, resources_pb2
2
from clarifai_grpc.grpc.api.status import status_code_pb2
3
4
# Insert here the initialization code as outlined on this page:
5
# https://docs.clarifai.com/api-guide/api-overview
6
7
post_annotations_searches_response = stub.PostAnnotationsSearches(
8
service_pb2.PostAnnotationsSearchesRequest(
9
searches = [
10
resources_pb2.Search(
11
query=resources_pb2.Query(
12
ranks=[
13
resources_pb2.Rank(
14
annotation=resources_pb2.Annotation(
15
data=resources_pb2.Data(
16
concepts=[ # You can search by multiple concepts.
17
resources_pb2.Concept(
18
name="犬", # You could search by concept ID as well.
19
language="ja", # japanese
20
value=1 # Value of 0 will search for images that don't have the concept.
21
)
22
]
23
)
24
)
25
)
26
]
27
)
28
)
29
]
30
),
31
metadata=metadata
32
)
33
34
if post_annotations_searches_response.status.code != status_code_pb2.SUCCESS:
35
print("There was an error with your request!")
36
print("\tCode: {}".format(post_annotations_searches_response.outputs[0].status.code))
37
print("\tDescription: {}".format(post_annotations_searches_response.outputs[0].status.description))
38
print("\tDetails: {}".format(post_annotations_searches_response.outputs[0].status.details))
39
raise Exception("Post searches failed, status: " + post_annotations_searches_response.status.description)
40
41
print("Search result:")
42
for hit in post_annotations_searches_response.hits:
43
print("\tScore %.2f for annotation: %s off input: %s" % (hit.score, hit.annotation.id, hit.input.id))
Copied!
1
#
2
# Value of 0 will search for images that don't have the concept.
3
#
4
# Instead of "name" you can search by "id" as well.
5
6
curl -X POST \
7
-H "Authorization: Key YOUR_API_KEY" \
8
-H "Content-Type: application/json" \
9
-d '
10
{
11
"searches": [
12
{
13
"query": {
14
"ranks": [
15
{
16
"annotation": {
17
"data": {
18
"concepts": [
19
{
20
"name":"犬",
21
"language": "ja",
22
"value": 1
23
}
24
]
25
}
26
}
27
}
28
]
29
}
30
}
31
]
32
}'\
33
https://api.clarifai.com/v2/annnotations/searches
Copied!
1
const raw = JSON.stringify({
2
"user_app_id": {
3
"user_id": "{YOUR_USER_ID}",
4
"app_id": "{YOUR_APP_ID}"
5
},
6
"searches": [
7
{
8
"query": {
9
"ranks": [
10
{
11
"annotation": {
12
"data": {
13
"concepts": [
14
{
15
"name":"犬",
16
"language": "ja",
17
"value": 1
18
}
19
]
20
}
21
}
22
}
23
]
24
}
25
}
26
]
27
});
28
29
const requestOptions = {
30
method: 'POST',
31
headers: {
32
'Accept': 'application/json',
33
'Authorization': 'Key {YOUR_PERSONAL_TOKEN}'
34
},
35
body: raw
36
};
37
38
fetch(`https://api.clarifai.com/v2/annnotations/searches`, requestOptions)
39
.then(response => response.text())
40
.then(result => console.log(result))
41
.catch(error => console.log('error', error));
Copied!

Search by visual similarity

You can use images to search through your collection. The API will return ranked results based on how similar the results are to the image you provided in your query.

Search by image URL

Java
NodeJS
Python
cURL
Javascript (REST)
1
import com.clarifai.grpc.api.*;
2
import com.clarifai.grpc.api.status.*;
3
4
// Insert here the initialization code as outlined on this page:
5
// https://docs.clarifai.com/api-guide/api-overview
6
7
MultiSearchResponse postAnnotationsSearchesResponse = stub.postAnnotationsSearches(
8
PostAnnotationsSearchesRequest.newBuilder().addSearches(
9
Search.newBuilder().setQuery(
10
Query.newBuilder().addRanks(
11
Rank.newBuilder().setAnnotation(
12
Annotation.newBuilder().setData(
13
Data.newBuilder().setImage(
14
Image.newBuilder()
15
.setUrl("{YOUR_IMAGE_URL}")
16
)
17
)
18
)
19
)
20
)
21
)
22
.build()
23
);
24
25
if (postAnnotationsSearchesResponse.getStatus().getCode() != StatusCode.SUCCESS) {
26
throw new RuntimeException("Post annotations searches failed, status: " + postAnnotationsSearchesResponse.getStatus());
27
}
28
29
System.out.println("Found inputs " + postAnnotationsSearchesResponse.getHitsCount() + ":");
30
for (Hit hit : postAnnotationsSearchesResponse.getHitsList()) {
31
System.out.printf("\tScore %.2f for annotation % of input %s\n", hit.getScore(), hit.getAnnotation().getId(), hit.getInput().getId())
32
}
Copied!
1
// Insert here the initialization code as outlined on this page:
2
// https://docs.clarifai.com/api-guide/api-overview
3
4
stub.PostAnnotationsSearches(
5
{
6
searches: [
7
{
8
query: {
9