From eaaeddd26a2d49874244f90f041a785b2b9b811c Mon Sep 17 00:00:00 2001 From: Zack Date: Mon, 25 Nov 2024 22:09:08 -0500 Subject: [PATCH] Update readme with usage examples and bump version --- README.md | 97 +++++++++++++++++++++++++++++++++++++++++++++++ gradle.properties | 2 +- 2 files changed, 98 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f0946ea5..94f7eb58 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,103 @@ A simple Java client for the Feature Server HTTP API that helps customers integr * [Tecton Java Client API Reference](https://www.javadoc.io/doc/ai.tecton/java-client/latest/index.html) * [Tecton Java Client Example Code](https://github.com/tecton-ai/TectonClientDemo/tree/main/src/main/java) +## Usage Example + +### Gradle Dependencies + +In your `build.gradle` file for your project, make sure you're using the central Maven repository: + +``` +repositories { + mavenCentral() + // ... +} +``` + +And then you can depend on the Tecton client library: + +``` +dependencies { + implementation "ai.tecton:java-client:$client_version" + // ... +} +``` + +### Client Usage + +Necessary imports: + +```java +import ai.tecton.client.TectonClient; +import ai.tecton.client.TectonClientOptions; +import ai.tecton.client.request.GetFeaturesBatchRequest; +import ai.tecton.client.request.GetFeaturesRequestData; +import ai.tecton.client.request.RequestConstants; +import ai.tecton.client.response.GetFeaturesBatchResponse; +import ai.tecton.client.response.GetFeaturesResponse; +import ai.tecton.client.model.ValueType; +``` + +You can instantiate a `TectonClient` object for querying a particular Tecton cluster as a particular +service account: + +```java +String apiKey = "apikey1"; +String tectonUrl = "mycluster.tecton.ai"; + +TectonClient tectonClient = new TectonClient(tectonUrl, apiKey); +``` + +You can then make a request for a single (composite) join key: + +```java +String workspaceName = "prod"; +String featureServiceName = "fraud_service"; +String featureName = "user_transaction_counts.feature_name"; + +GetFeaturesRequestData getFeaturesRequestData = + new GetFeaturesRequestData() + .addJoinKey("user_id", "user_205125746682") + .addJoinKey("merchant", "entertainment") + .addRequestContext("amt", 500.00); +GetFeaturesRequest req = + new GetFeaturesRequest(workspaceName, featureServiceName, getFeaturesRequestData); + +GetFeaturesResponse resp = tectonClient.getFeatures(req); +Map featureValues = resp.getFeatureValuesAsMap(); +// Could also use getFeaturesResponse.getFeatureValues() for a List. + +FeatureValue sampleFeatureValue = featureValues.get(featureName); + +// Will be "user_transaction_counts". +String fns = sampleFeatureValue.getFeatureNamespace(); + +// Will be "feature_name". +String fn = sampleFeatureValue.getFeatureName(); + +// Will be ValueType.INT64. +ValueType vt = sampleFeatureValue.getValueType(); + +// Will be the value of the feature. +Long v = sampleFeatureValue.int64value(); + +// Other methods are available for other value types, such as: +// stringValue(), booleanValue(), float64Value(), float64ArrayValue(), +// float32ArrayValue(), int64ArrayValue(), and stringArrayValue(). +``` + +Or you can make a batch request for multiple join keys: + +```java +List requestDataList = new ArrayList<>(); +requestDataList.add(getFeaturesRequestData); +GetFeaturesBatchRequest batchRequest = new GetFeaturesBatchRequest(workspaceName, featureServiceName, getFeaturesRequestDataList, RequestConstants.DEFAULT_METADATA_OPTIONS, 5); +GetFeaturesBatchResponse batchResponse = tectonClient.getFeaturesBatch(batchRequest); + +// Same as resp above. +GetFeaturesResponse sampleResponse = batchResponse.getBatchResponseList().get(0); +``` + ## Troubleshooting If you have any questions or need help, diff --git a/gradle.properties b/gradle.properties index 39bb88eb..42f95471 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ -version=0.9.1-SNAPSHOT +version=0.9.2-SNAPSHOT ossrh.username=tecton-team