Knowledge Graph
Connect the knowledge gained by different models
The Knowledge Graph uses Clarifai's concept mapping model to establish a hierarchical relationship between your concepts.
It uses three different predicates to organize your concepts: hypernyms, hyponyms, and synonyms.
Hyponym — represents an 'is a kind of' relation. For example, the relationship described as 'honey' (subject), 'hyponym' (predicate), 'food' (object) is more easily read as 'honey' 'is a kind of' 'food'.
Hypernym — is the opposite of 'hyponym'. When you add the relationship, the opposite will automatically appear in your queries. An 'hypernym' can be read as 'is a parent of'. For example, 'food' (subject), 'hypernym' (predicate), 'honey' (object) is more easily read as 'food' is a parent of 'honey'.
Synonym — defines two concepts that essentially mean the same thing. This is more like an "is" relationship. For example, a 'synonym' relationship could be "puppy" is "pup". The reverse is also true if the former is added; so, "pup" is "puppy" will appear in queries as well.
Create Relations
To create a relation between two concepts, you first have to create them in your custom model. See the Concepts section on how to do that programatically.
Each relation should have a specified predicate, which can be hyponym, hypernym, or synonym.
Below is an example of how to create a relation between two concepts.
The initialization code used in the following examples is outlined in detail on the client installation page.
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
- cURL
###################################################################################
# In this section, we set the user authentication, app ID, subject concept ID,
# object concept ID, and predicate. Change these strings to run your own example.
###################################################################################
USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these to whatever relations you want to create
SUBJECT_CONCEPT_ID = 'honey'
OBJECT_CONCEPT_ID = 'food'
PREDICATE = "hypernym" # This can be hypernym, hyponym, or synonym
##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', 'Key ' + PAT),)
post_concept_relation_response = stub.PostConceptRelations(
service_pb2.PostConceptRelationsRequest(
user_app_id=resources_pb2.UserAppIDSet(
user_id=USER_ID,
app_id=APP_ID
),
concept_id=SUBJECT_CONCEPT_ID,
concept_relations=[
resources_pb2.ConceptRelation(
object_concept=resources_pb2.Concept(id=OBJECT_CONCEPT_ID),
predicate=PREDICATE
)
]
),
metadata=metadata
)
if post_concept_relation_response.status.code != status_code_pb2.SUCCESS:
print(post_concept_relation_response.status)
raise Exception("Post concept relation failed, status: " + post_concept_relation_response.status.description)
print(post_concept_relation_response)
<!--index.html file-->
<script>
////////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, subject concept ID,
// object concept ID, and predicate. Change these strings to run your own example.
///////////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these to whatever relations you want to create
const SUBJECT_CONCEPT_ID = 'honey';
const OBJECT_CONCEPT_ID = 'food';
const PREDICATE = "hypernym"; // This can be hypernym, hyponym, or synonym
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const raw = JSON.stringify({
"user_app_id": {
"user_id": USER_ID,
"app_id": APP_ID
},
"concept_relations": [
{
"object_concept": {
"id": OBJECT_CONCEPT_ID
},
"predicate": PREDICATE
}
]
});
const requestOptions = {
method: 'POST',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT
},
body: raw
};
fetch("https://api.clarifai.com/v2/users/me/apps/" + APP_ID + "/concepts/" + SUBJECT_CONCEPT_ID + "/relations", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
</script>
//index.js file
////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, subject concept ID,
// object concept ID, and predicate. Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these to whatever relations you want to create
const SUBJECT_CONCEPT_ID = 'honey';
const OBJECT_CONCEPT_ID = 'food';
const PREDICATE = "hypernym"; // This can be hypernym, hyponym, or synonym.
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.PostConceptRelations(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
concept_id: SUBJECT_CONCEPT_ID,
concept_relations: [
{
object_concept: {
id: OBJECT_CONCEPT_ID,
},
predicate: PREDICATE
}
]
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Create concept relations failed, status: " + response.status.description);
}
}
);
package com.clarifai.example;
import com.clarifai.grpc.api.*;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.status.StatusCode;
public class ClarifaiExample {
///////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, subject concept ID,
// object concept ID, and predicate. Change these strings to run your own example.
///////////////////////////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";
//Your PAT (Personal Access Token) can be found in the portal under Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change these to whatever relations you want to create
static final String SUBJECT_CONCEPT_ID = "honey";
static final String OBJECT_CONCEPT_ID = "food";
static final String PREDICATE = "hypernym"; // This can be hypernym, hyponym, or synonym
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
MultiConceptRelationResponse postConceptRelationsResponse = stub.postConceptRelations(
PostConceptRelationsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID).build())
.setConceptId(SUBJECT_CONCEPT_ID)
.addConceptRelations(
ConceptRelation.newBuilder()
.setObjectConcept(Concept.newBuilder().setId(OBJECT_CONCEPT_ID).build())
.setPredicate(PREDICATE).build())
.build()
);
if (postConceptRelationsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Post concept relations failed, status: " + postConceptRelationsResponse.getStatus());
}
System.out.println(postConceptRelationsResponse);
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
////////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, subject concept ID,
// object concept ID, and predicate. Change these strings to run your own example.
///////////////////////////////////////////////////////////////////////////////////////////
$USER_ID = "YOUR_USER_ID_HERE";
// Your PAT (Personal Access Token) can be found in the Account's Security section
$PAT = "YOUR_PAT_HERE";
$APP_ID = "YOUR_APP_ID_HERE";
// Change these to whatever relations you want to create
$SUBJECT_CONCEPT_ID = "honey";
$OBJECT_CONCEPT_ID = "food";
$PREDICATE = "hypernym"; // This can be hypernym, hyponym, or synonym
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\PostConceptRelationsRequest;
use Clarifai\Api\ConceptRelation;
use Clarifai\Api\Concept;
use Clarifai\Api\Status\StatusCode;
use Clarifai\Api\UserAppIDSet;
$client = ClarifaiClient::grpc();
$metadata = ["Authorization" => ["Key " . $PAT]];
$userDataObject = new UserAppIDSet([
"user_id" => $USER_ID,
"app_id" => $APP_ID
]);
// Let's make a RPC call to the Clarifai platform. It uses the opened gRPC client channel to communicate a
// request and then wait for the response
[$response, $status] = $client->PostConceptRelations(
// The request object carries the request along with the request status and other metadata related to the request itself
new PostConceptRelationsRequest([
"user_app_id" => $userDataObject,
"concept_id" => $SUBJECT_CONCEPT_ID,
"concept_relations" => [
new ConceptRelation([
"object_concept" => new Concept(["id" => $OBJECT_CONCEPT_ID ]),
"predicate" => $PREDICATE
])
]
]),
$metadata
)->wait();
// A response is returned and the first thing we do is check the status of it
// A successful response will have a status code of 0; otherwise, there is some error
if ($status->code !== 0) {
throw new Exception("Error: {$status->details}");
}
// In addition to the RPC response status, there is a Clarifai API status that reports if the operation was a success or failure
// (not just that the communication was successful)
if ($response->getStatus()->getCode() != StatusCode::SUCCESS) {
print $response->getStatus()->getDetails();
throw new Exception("Failure response: " . $response->getStatus()->getDescription());
}
print $response->serializeToJsonString();
?>
curl -X POST "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/concepts/YOUR_SUBJECT_CONCEPT_ID_HERE/relations" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
--data-raw '{
"concept_relations": [
{
"object_concept": {
"id": "YOUR_OBJECT_CONCEPT_ID_HERE"
},
"predicate": "hypernym"
}
]
}'
Raw Output Example
status {
code: SUCCESS
description: "Ok"
req_id: "0d0a5ec5df14d62a7d660f392ce26727"
}
concept_relations {
id: "2d794e5ede534500b4ac7da44ef570ee"
subject_concept {
id: "honey"
name: "honey"
value: 1.0
created_at {
seconds: 1643976334
nanos: 237961000
}
language: "en"
app_id: "a39423543bb941bf9ba2ee95fad11f0a"
visibility {
gettable: PRIVATE
}
user_id: "e5y2lteoz3s3iy"
}
object_concept {
id: "food"
name: "food"
value: 1.0
created_at {
seconds: 1643976326
nanos: 123719000
}
language: "en"
app_id: "a39423543bb941bf9ba2ee95fad11f0a"
visibility {
gettable: PRIVATE
}
user_id: "ei2leoz3s3iy"
}
predicate: "hypernym"
visibility {
gettable: PRIVATE
}
}
List Existing Relations
Below is an example of how to list existing relations between concepts.
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
- cURL
######################################################################################
# In this section, we set the user authentication, app ID, concept ID, and predicate.
# Change these strings to run your own example.
######################################################################################
USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these to whatever concept you want to list its relations
CONCEPT_ID = 'honey'
PREDICATE = "hypernym" # This is optional. If skipped, all concept's relations will be returned
##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', 'Key ' + PAT),)
list_concept_relation_response = stub.ListConceptRelations(
service_pb2.ListConceptRelationsRequest(
user_app_id=resources_pb2.UserAppIDSet(
user_id=USER_ID,
app_id=APP_ID
),
concept_id=CONCEPT_ID,
predicate=PREDICATE
),
metadata=metadata
)
if list_concept_relation_response.status.code != status_code_pb2.SUCCESS:
print(list_concept_relation_response.status)
raise Exception("List concept relation failed, status: " + list_concept_relation_response.status.description)
for relation in list_concept_relation_response.concept_relations:
print(relation)
<!--index.html file-->
<script>
////////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, concept ID, and predicate.
// Change these strings to run your own example.
///////////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these to whatever concept you want to list its relations
CONCEPT_ID = 'honey';
PREDICATE = "hypernym"; // This is optional. If skipped, all concept's relations will be returned
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const requestOptions = {
method: 'GET',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT
},
};
fetch("https://api.clarifai.com/v2/users/" + USER_ID + "/apps/" + APP_ID + "/concepts/" + CONCEPT_ID + "/relations?predicate=" + PREDICATE, requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
</script>
//index.js file
///////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, concept ID, and predicate.
// Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these to whatever concept you want to list its relations
const CONCEPT_ID = 'honey';
const PREDICATE = "hypernym"; // This is optional. If skipped, all concept's relations will be returned
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.ListConceptRelations(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
concept_id: CONCEPT_ID,
predicate: PREDICATE
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("List concept relations failed, status: " + response.status.description);
}
for (const relation of response.concept_relations) {
console.log(relation);
}
}
);
package com.clarifai.example;
import com.clarifai.grpc.api.*;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.status.StatusCode;
public class ClarifaiExample {
////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, concept ID, and predicate.
// Change these strings to run your own example.
////////////////////////////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";
//Your PAT (Personal Access Token) can be found in the portal under Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change these to whatever concept you want to list its relations
static final String CONCEPT_ID = "honey";
static final String PREDICATE = "hypernym"; // This is optional. If skipped, all concept's relations will be returned
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
MultiConceptRelationResponse listConceptRelationsResponse = stub.listConceptRelations(
ListConceptRelationsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID).build())
.setConceptId(CONCEPT_ID)
.setPredicate(PREDICATE)
.build()
);
if (listConceptRelationsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("List concept relations failed, status: " + listConceptRelationsResponse.getStatus());
}
for (ConceptRelation relation: listConceptRelationsResponse.getConceptRelationsList()) {
System.out.println(relation);
}
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
////////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, concept ID, and predicate.
// Change these strings to run your own example.
///////////////////////////////////////////////////////////////////////////////////////////
$USER_ID = "YOUR_USER_ID_HERE";
// Your PAT (Personal Access Token) can be found in the Account's Security section
$PAT = "YOUR_PAT_HERE";
$APP_ID = "YOUR_APP_ID_HERE";
// Change these to whatever concept you want to list its relations
$CONCEPT_ID = 'honey';
$PREDICATE = "hypernym"; // This is optional. If skipped, all concept's relations will be returned
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\ListConceptRelationsRequest;
use Clarifai\Api\Status\StatusCode;
use Clarifai\Api\UserAppIDSet;
$client = ClarifaiClient::grpc();
$metadata = ["Authorization" => ["Key " . $PAT]];
$userDataObject = new UserAppIDSet([
"user_id" => $USER_ID,
"app_id" => $APP_ID
]);
// Let's make a RPC call to the Clarifai platform. It uses the opened gRPC client channel to communicate a
// request and then wait for the response
[$response, $status] = $client->ListConceptRelations(
// The request object carries the request along with the request status and other metadata related to the request itself
new ListConceptRelationsRequest([
"user_app_id" => $userDataObject,
"concept_id" => $CONCEPT_ID,
"predicate" => $PREDICATE
]),
$metadata
)->wait();
// A response is returned and the first thing we do is check the status of it
// A successful response will have a status code of 0; otherwise, there is some error
if ($status->code !== 0) {
throw new Exception("Error: {$status->details}");
}
// In addition to the RPC response status, there is a Clarifai API status that reports if the operation was a success or failure
// (not just that the communication was successful)
if ($response->getStatus()->getCode() != StatusCode::SUCCESS) {
print $response->getStatus()->getDetails();
throw new Exception("Failure response: " . $response->getStatus()->getDescription());
}
foreach ($response->getConceptRelations() as $concept) {
echo $concept->SerializeToJsonString() . "</br>";
}
?>
# Setting the predicate parameter is optional. If skipped, all concept's relations will be returned.
curl -X GET "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/concepts/YOUR_CONCEPT_ID_HERE/relations?predicate=hypernym" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json"
Raw Output Example
id: "2d794e5ede534500b4ac7da44ef570ee"
subject_concept {
id: "honey"
name: "honey"
value: 1.0
created_at {
seconds: 1643976334
nanos: 237961000
}
language: "en"
app_id: "a39423543bb941bf9ba2ee95fad11f0a"
visibility {
gettable: PRIVATE
}
user_id: "ei2leoz3s3iy"
}
object_concept {
id: "food"
name: "food"
value: 1.0
created_at {
seconds: 1643976326
nanos: 123719000
}
language: "en"
app_id: "a39423543bb941bf9ba2ee95fad11f0a"
visibility {
gettable: PRIVATE
}
user_id: "ei2leoz3s3iy"
}
predicate: "hypernym"
visibility {
gettable: PRIVATE
}
Delete Relations
Below is an example of how to delete relations between concepts.
You can use either of the following ways to retrieve the CONCEPT_RELATION_IDS
:
- Use the above List Existing Relations method to list ALL existing relations between concepts. Remember to omit the
predicate
parameter. - Log in to the Portal and access the relations details of your concept. Then, inspect the network activity under your browser's Network Tab. The IDs are under the
relations
category.
- Python
- JavaScript (REST)
- NodeJS
- Java
- PHP
- cURL
###################################################################################
# In this section, we set the user authentication, app ID, object concept ID, and
# concept relation IDs. Change these strings to run your own example.
####################################################################################
USER_ID = 'YOUR_USER_ID_HERE'
# Your PAT (Personal Access Token) can be found in the Account's Security section
PAT = 'YOUR_PAT_HERE'
APP_ID = 'YOUR_APP_ID_HERE'
# Change these to whatever relations you want to delete
OBJECT_CONCEPT_ID = 'YOUR_OBJECT_CONCEPT_ID_HERE'
CONCEPT_RELATION_IDS = ['0d9b0acb10fb4dac9a9d60a149d8fc5c','f5acf9c2a76143d78daf5f984693c52c']
##########################################################################
# YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
##########################################################################
from clarifai_grpc.channel.clarifai_channel import ClarifaiChannel
from clarifai_grpc.grpc.api import resources_pb2, service_pb2, service_pb2_grpc
from clarifai_grpc.grpc.api.status import status_code_pb2
channel = ClarifaiChannel.get_grpc_channel()
stub = service_pb2_grpc.V2Stub(channel)
metadata = (('authorization', 'Key ' + PAT),)
delete_concept_relation_response = stub.DeleteConceptRelations(
service_pb2.DeleteConceptRelationsRequest(
user_app_id=resources_pb2.UserAppIDSet(
user_id=USER_ID,
app_id=APP_ID
),
concept_id=OBJECT_CONCEPT_ID,
ids=CONCEPT_RELATION_IDS
),
metadata=metadata
)
if delete_concept_relation_response.status.code != status_code_pb2.SUCCESS:
print(delete_concept_relation_response.status)
raise Exception("Delete concept relation failed, status: " + delete_concept_relation_response.status.description)
<!--index.html file-->
<script>
////////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, object concept ID, and
// concept relation IDs. Change these strings to run your own example.
///////////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these to whatever relations you want to delete
const OBJECT_CONCEPT_ID = 'YOUR_OBJECT_CONCEPT_ID_HERE';
const CONCEPT_RELATION_IDS = ['0d9b0acb10fb4dac9a9d60a149d8fc5c','f5acf9c2a76143d78daf5f984693c52c'];
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const raw = JSON.stringify({
"ids": CONCEPT_RELATION_IDS
});
const requestOptions = {
method: 'DELETE',
headers: {
'Accept': 'application/json',
'Authorization': 'Key ' + PAT
},
body: raw
};
fetch("https://api.clarifai.com/v2/users/" + USER_ID + "/apps/" + APP_ID + "/concepts/" + OBJECT_CONCEPT_ID + "/relations", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
</script>
//index.js file
//////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, object concept ID, and
// concept relation IDs. Change these strings to run your own example.
//////////////////////////////////////////////////////////////////////////////////////
const USER_ID = 'YOUR_USER_ID_HERE';
// Your PAT (Personal Access Token) can be found in the Account's Security section
const PAT = 'YOUR_PAT_HERE';
const APP_ID = 'YOUR_APP_ID_HERE';
// Change these to whatever relations you want to delete
const OBJECT_CONCEPT_ID = 'YOUR_OBJECT_CONCEPT_ID_HERE';
const CONCEPT_RELATION_IDS = ['0d9b0acb10fb4dac9a9d60a149d8fc5c','f5acf9c2a76143d78daf5f984693c52c'];
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
const { ClarifaiStub, grpc } = require("clarifai-nodejs-grpc");
const stub = ClarifaiStub.grpc();
// This will be used by every Clarifai endpoint call
const metadata = new grpc.Metadata();
metadata.set("authorization", "Key " + PAT);
stub.DeleteConceptRelations(
{
user_app_id: {
"user_id": USER_ID,
"app_id": APP_ID
},
concept_id: OBJECT_CONCEPT_ID,
ids: CONCEPT_RELATION_IDS
},
metadata,
(err, response) => {
if (err) {
throw new Error(err);
}
if (response.status.code !== 10000) {
throw new Error("Delete concept relations failed, status: " + response.status.description);
}
}
);
package com.clarifai.example;
import com.clarifai.grpc.api.*;
import com.clarifai.channel.ClarifaiChannel;
import com.clarifai.credentials.ClarifaiCallCredentials;
import com.clarifai.grpc.api.status.BaseResponse;
import com.clarifai.grpc.api.status.StatusCode;
public class ClarifaiExample {
/////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, object concept ID, and
// concept relation IDs. Change these strings to run your own example.
/////////////////////////////////////////////////////////////////////////////////////
static final String USER_ID = "YOUR_USER_ID_HERE";
//Your PAT (Personal Access Token) can be found in the portal under Authentication
static final String PAT = "YOUR_PAT_HERE";
static final String APP_ID = "YOUR_APP_ID_HERE";
// Change these to whatever relations you want to delete
static final String OBJECT_CONCEPT_ID = "YOUR_OBJECT_CONCEPT_ID_HERE";
static final String CONCEPT_RELATION_ID_1 = "0d9b0acb10fb4dac9a9d60a149d8fc5c";
static final String CONCEPT_RELATION_ID_2 = "f5acf9c2a76143d78daf5f984693c52c";
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
public static void main(String[] args) {
V2Grpc.V2BlockingStub stub = V2Grpc.newBlockingStub(ClarifaiChannel.INSTANCE.getGrpcChannel())
.withCallCredentials(new ClarifaiCallCredentials(PAT));
BaseResponse deleteConceptRelationsResponse = stub.deleteConceptRelations(
DeleteConceptRelationsRequest.newBuilder()
.setUserAppId(UserAppIDSet.newBuilder().setUserId(USER_ID).setAppId(APP_ID).build())
.addIds(CONCEPT_RELATION_ID_1)
.addIds(CONCEPT_RELATION_ID_2)
.setConceptId(OBJECT_CONCEPT_ID)
.build()
);
if (deleteConceptRelationsResponse.getStatus().getCode() != StatusCode.SUCCESS) {
throw new RuntimeException("Delete concept relations failed, status: " + deleteConceptRelationsResponse.getStatus());
}
}
}
<?php
require __DIR__ . "/vendor/autoload.php";
////////////////////////////////////////////////////////////////////////////////////////////
// In this section, we set the user authentication, app ID, object concept ID, and
// concept relation IDs. Change these strings to run your own example.
///////////////////////////////////////////////////////////////////////////////////////////
$USER_ID = "YOUR_USER_ID_HERE";
// Your PAT (Personal Access Token) can be found in the Account's Security section
$PAT = "YOUR_PAT_HERE";
$APP_ID = "YOUR_APP_ID_HERE";
// Change these to whatever relations you want to delete
$OBJECT_CONCEPT_ID = "YOUR_OBJECT_CONCEPT_ID_HERE";
$CONCEPT_RELATION_IDS = ["0d9b0acb10fb4dac9a9d60a149d8fc5c","f5acf9c2a76143d78daf5f984693c52c"];
///////////////////////////////////////////////////////////////////////////////////
// YOU DO NOT NEED TO CHANGE ANYTHING BELOW THIS LINE TO RUN THIS EXAMPLE
///////////////////////////////////////////////////////////////////////////////////
use Clarifai\ClarifaiClient;
use Clarifai\Api\DeleteConceptRelationsRequest;
use Clarifai\Api\Status\StatusCode;
use Clarifai\Api\UserAppIDSet;
$client = ClarifaiClient::grpc();
$metadata = ["Authorization" => ["Key " . $PAT]];
$userDataObject = new UserAppIDSet([
"user_id" => $USER_ID,
"app_id" => $APP_ID
]);
// Let's make a RPC call to the Clarifai platform. It uses the opened gRPC client channel to communicate a
// request and then wait for the response
[$response, $status] = $client->DeleteConceptRelations(
// The request object carries the request along with the request status and other metadata related to the request itself
new DeleteConceptRelationsRequest([
"user_app_id" => $userDataObject,
"concept_id" => $OBJECT_CONCEPT_ID,
"ids" => $CONCEPT_RELATION_IDS
]),
$metadata
)->wait();
// A response is returned and the first thing we do is check the status of it
// A successful response will have a status code of 0; otherwise, there is some error
if ($status->code !== 0) {
throw new Exception("Error: {$status->details}");
}
// In addition to the RPC response status, there is a Clarifai API status that reports if the operation was a success or failure
// (not just that the communication was successful)
if ($response->getStatus()->getCode() != StatusCode::SUCCESS) {
print $response->getStatus()->getDetails();
throw new Exception("Failure response: " . $response->getStatus()->getDescription());
}
?>
curl -X DELETE "https://api.clarifai.com/v2/users/YOUR_USER_ID_HERE/apps/YOUR_APP_ID_HERE/concepts/YOUR_OBJECT_CONCEPT_ID_HERE/relations" \
-H "Authorization: Key YOUR_PAT_HERE" \
-H "Content-Type: application/json" \
--data-raw '{
"ids": [
"CONCEPT_RELATION_ID_1", "CONCEPT_RELATION_ID_2"
]
}'