Skip to main content

Create, Get, Update, Delete

Manage your concepts


Within your app, you can create concepts, modify them after creation, or get them from your app.

caution

We currently do not support deleting concepts since they have such an integral tie across almost all other data structures in the platform, like inputs, models, searches, etc.

You will find that some of our endpoints have additional information returned from the clarifai/main app, which contains our pre-trained models and a large knowledge graph we've assembled over the years.

Create

Add Concepts

To create a new concept in your app, you POST the concept with an id and name. You can also post more than one concept in the same request by sending a list of concepts.

Below is an example of how to add concepts.

info

The initialization code used in the following examples is outlined in detail on the client installation page.

################################################################################
# In this section, we set the user authentication, app ID, concept ID and name.
# 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 concepts you want to process
CONCEPT_ID = 'cat'
CONCEPT_NAME = 'Cat Name'

##########################################################################
# 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),)

userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)

post_concepts_response = stub.PostConcepts(
service_pb2.PostConceptsRequest(
user_app_id=userDataObject,
concepts=[resources_pb2.Concept(id=CONCEPT_ID, name=CONCEPT_NAME)]
),
metadata=metadata
)

if post_concepts_response.status.code != status_code_pb2.SUCCESS:
print(post_concepts_response.status)
raise Exception("Post concept failed, status: " + post_concepts_response.status.description)

print(post_concepts_response)
JSON Output Example
status {
code: SUCCESS
description: "Ok"
req_id: "9852fce206578f4bc5b6bed38f03eed8"
}
concepts {
id: "cat"
name: "Cat Name"
value: 1.0
created_at {
seconds: 1643890626
nanos: 775078265
}
language: "en"
app_id: "a39423543bb941bf9ba2ee95fad11f0a"
visibility {
gettable: PRIVATE
}
user_id: "ei2l2oz3s3iz"
}

Get

Get Concept by ID

Below is an example of how to get a single concept by its ID.

###########################################################################
# In this section, we set the user authentication, app ID, and concept ID.
# 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 this to whatever concept you want to retrieve
CONCEPT_ID = 'cat'

##########################################################################
# 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),)

userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)

get_concepts_response = stub.GetConcept(
service_pb2.GetConceptRequest(
user_app_id=userDataObject,
concept_id=CONCEPT_ID
),
metadata=metadata
)

if get_concepts_response.status.code != status_code_pb2.SUCCESS:
print(get_concepts_response.status)
raise Exception("Get concept failed, status: " + get_concepts_response.status.description)

print(get_concepts_response)
JSON Output Example
status {
code: SUCCESS
description: "Ok"
req_id: "240b8fa082722b0f137c09ec5141cfa3"
}
concept {
id: "cat"
name: "Cat Name"
value: 1.0
created_at {
seconds: 1643890626
nanos: 775078000
}
language: "en"
app_id: "a39423543bb941bf9ba2ee95fad11f0a"
visibility {
gettable: PRIVATE
}
user_id: "ei2l2oz3s3iz"
}

List Concepts

You can get a list of concepts within your app with a GET call. This call supports pagination.

Below is an example of how to list concepts.

###########################################################################
# In this section, we set the user authentication.
# 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'

##########################################################################
# 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),)

userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)

list_concepts_response = stub.ListConcepts(
service_pb2.ListConceptsRequest(user_app_id=userDataObject),
metadata=metadata
)

if list_concepts_response.status.code != status_code_pb2.SUCCESS:
print(list_concepts_response.status)
raise Exception("List concept failed, status: " + list_concepts_response.status.description)

print(list_concepts_response)
JSON Output Example
status {
code: SUCCESS
description: "Ok"
req_id: "1155d18c386559cfdaa22274a0531d9f"
}
concepts {
id: "cat"
name: "Cat Name"
value: 1.0
created_at {
seconds: 1643890626
nanos: 775078000
}
language: "en"
app_id: "a39423543bb941bf9ba2ee95fad11f0a"
visibility {
gettable: PRIVATE
}
user_id: "ei2leoz3s3iy"
}
concepts {
id: "charlie"
name: "Charlie Name"
value: 1.0
created_at {
seconds: 1643865054
nanos: 92351000
}
language: "en"
app_id: "a39423543bb941bf9ba2ee95fad11f0a"
visibility {
gettable: PRIVATE
}
user_id: "ei2l2oz3s3iz"
}

List Model Concepts

You can get a list of concepts within your model with a GET call. This call supports pagination.

Below is an example of how to list the concepts in your model.

note

If you are using any of the Clarifai gRPC clients, the ListModelConcepts endpoint, which lists concepts in a model, is only available from release 8.10.0.

###########################################################################
# In this section, we set the user authentication and model ID.
# 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 this to whatever model you want to retrieve its concepts
MODEL_ID = 'YOUR_MODEL_ID_HERE'

##########################################################################
# 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),)

userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)

list_model_concepts_response = stub.ListModelConcepts(
service_pb2.ListModelConceptsRequest(
user_app_id=userDataObject,
model_id=MODEL_ID
),
metadata=metadata
)

if list_model_concepts_response.status.code != status_code_pb2.SUCCESS:
print(list_model_concepts_response.status)
raise Exception("List model concept failed, status: " + list_model_concepts_response.status.description)

print(list_model_concepts_response)

Update

Update Concept Name

Below is an example of how to update a concept's name given its id by using the "overwrite" action. You can also patch multiple concepts by sending a list of concepts.

################################################################################
# In this section, we set the user authentication, app ID, concept ID and name.
# 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 update
CONCEPT_ID = 'cat'
CONCEPT_NAME = 'New Cat Name'

##########################################################################
# 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),)

userDataObject = resources_pb2.UserAppIDSet(user_id=USER_ID, app_id=APP_ID)

patch_concepts_response = stub.PatchConcepts(
service_pb2.PatchConceptsRequest(
user_app_id=userDataObject,
action="overwrite", # The only supported action right now is overwrite
concepts=[resources_pb2.Concept(id=CONCEPT_ID, name=CONCEPT_NAME)]
),
metadata=metadata
)

if patch_concepts_response.status.code != status_code_pb2.SUCCESS:
print(patch_concepts_response.status)
raise Exception("Patch concept failed, status: " + patch_concepts_response.status.description)

print(patch_concepts_response)
JSON Output Example
status {
code: SUCCESS
description: "Ok"
req_id: "67ba891f905e081690e4e94522fc21c7"
}
concepts {
id: "cat"
name: "New Cat Name"
value: 1.0
created_at {
seconds: 1643897414
nanos: 497920914
}
language: "en"
app_id: "a39423543bb941bf9ba2ee95fad11f0a"
user_id: "ei2l2oz3s3iz"
}