Read Online Features for Inference using the Java Client
Tecton provides an open-source client library in Java for reading features from the online store. See the Java Client Demo repo for sample usage of the Java Client.
The Java Client API Reference can be found here.
Adding the Java Client dependency​
The latest version of the Tecton Java Client can be found on Maven.
For a Maven project, add the following dependency to the pom.xml
:
<dependency>
<groupId>ai.tecton</groupId>
<artifactId>java-client</artifactId>
<version>0.1.0</version>
</dependency>
For a Gradle project, add the following to the build.gradle
:
repositories {
mavenCentral()
}
dependencies {
implementation 'ai.tecton:java-client:0.1.0'
}
Creating an API key to authenticate to the HTTP API​
To authenticate your requests to the HTTP API, you will need to create a Service Account to obtain an API key, and grant that Service Account the Consumer role for your workspace:
- Create a Service Account to obtain your API key.
tecton service-account create \
--name "sample-service-account" \
--description "An online inference sample"
Output:
Save this API Key - you will not be able to get it again.
API Key: <Your-api-key>
Service Account ID: <Your-Service-Account-Id>
- Assign the Consumer role to the Service Account.
tecton access-control assign-role --role consumer \
--workspace <Your-workspace> \
--service-account <Your-Service-Account-Id>
Output:
Successfully updated role.
Save this API key for the next step.
Creating a TectonClient
Object​
Create a TectonClient
object with your Tecton instance base URL
(https://<your Tecton instance prefix>.tecton.ai
) and your API key:
TectonClient tectonClient = new TectonClient(url, apiKey);
Calling the get-features
Endpoint​
To call the get-features
endpoint using the client, create objects from the
GetFeaturesRequestData
and GetFeaturesRequest
classes.
GetFeaturesRequestData getFeaturesRequestData =
new GetFeaturesRequestData()
.addJoinKey("user_id", "123")
.addJoinKey("merchant", "xyz")
.addRequestContext("amt", 500.00);
GetFeaturesRequest getFeaturesRequest = new GetFeaturesRequest("<Your-workspace>","fraud_detection_feature_service", getFeaturesRequestData);
Now, call the getFeatures()
method in the tectonClient
and pass the
getFeaturesRequest
object as a parameter.
This method:
- Creates an HTTP request using the URL, apiKey and the
getFeaturesRequest
object - Calls the FeatureService API
- Receives the response from the API and deserializes it into the
getFeaturesResponse
object
GetFeaturesResponse getFeaturesResponse = tectonClient.getFeatures(getFeaturesRequest);
The feature vector can be accessed as a list from the getFeaturesResponse
using the getFeatureValues()
method.
GetFeaturesResponse getFeaturesResponse = tectonClient.getFeatures(getFeaturesRequest);