@@ -9,6 +9,103 @@ A simple Java client for the Feature Server HTTP API that helps customers integr
9
9
* [ Tecton Java Client API Reference] ( https://www.javadoc.io/doc/ai.tecton/java-client/latest/index.html )
10
10
* [ Tecton Java Client Example Code] ( https://github.com/tecton-ai/TectonClientDemo/tree/main/src/main/java )
11
11
12
+ ## Usage Example
13
+
14
+ ### Gradle Dependencies
15
+
16
+ In your ` build.gradle ` file for your project, make sure you're using the central Maven repository:
17
+
18
+ ```
19
+ repositories {
20
+ mavenCentral()
21
+ // ...
22
+ }
23
+ ```
24
+
25
+ And then you can depend on the Tecton client library:
26
+
27
+ ```
28
+ dependencies {
29
+ implementation "ai.tecton:java-client:$client_version"
30
+ // ...
31
+ }
32
+ ```
33
+
34
+ ### Client Usage
35
+
36
+ Necessary imports:
37
+
38
+ ``` java
39
+ import ai.tecton.client.TectonClient ;
40
+ import ai.tecton.client.TectonClientOptions ;
41
+ import ai.tecton.client.request.GetFeaturesBatchRequest ;
42
+ import ai.tecton.client.request.GetFeaturesRequestData ;
43
+ import ai.tecton.client.request.RequestConstants ;
44
+ import ai.tecton.client.response.GetFeaturesBatchResponse ;
45
+ import ai.tecton.client.response.GetFeaturesResponse ;
46
+ import ai.tecton.client.model.ValueType ;
47
+ ```
48
+
49
+ You can instantiate a ` TectonClient ` object for querying a particular Tecton cluster as a particular
50
+ service account:
51
+
52
+ ``` java
53
+ String apiKey = " apikey1" ;
54
+ String tectonUrl = " mycluster.tecton.ai" ;
55
+
56
+ TectonClient tectonClient = new TectonClient (tectonUrl, apiKey);
57
+ ```
58
+
59
+ You can then make a request for a single (composite) join key:
60
+
61
+ ``` java
62
+ String workspaceName = " prod" ;
63
+ String featureServiceName = " fraud_service" ;
64
+ String featureName = " user_transaction_counts.feature_name" ;
65
+
66
+ GetFeaturesRequestData getFeaturesRequestData =
67
+ new GetFeaturesRequestData ()
68
+ .addJoinKey(" user_id" , " user_205125746682" )
69
+ .addJoinKey(" merchant" , " entertainment" )
70
+ .addRequestContext(" amt" , 500.00 );
71
+ GetFeaturesRequest req =
72
+ new GetFeaturesRequest (workspaceName, featureServiceName, getFeaturesRequestData);
73
+
74
+ GetFeaturesResponse resp = tectonClient. getFeatures(req);
75
+ Map<String , FeatureValue > featureValues = resp. getFeatureValuesAsMap();
76
+ // Could also use getFeaturesResponse.getFeatureValues() for a List<FeatureValue>.
77
+
78
+ FeatureValue sampleFeatureValue = featureValues. get(featureName);
79
+
80
+ // Will be "user_transaction_counts".
81
+ String fns = sampleFeatureValue. getFeatureNamespace();
82
+
83
+ // Will be "feature_name".
84
+ String fn = sampleFeatureValue. getFeatureName();
85
+
86
+ // Will be ValueType.INT64.
87
+ ValueType vt = sampleFeatureValue. getValueType();
88
+
89
+ // Will be the value of the feature.
90
+ Long v = sampleFeatureValue. int64value();
91
+
92
+ // Other methods are available for other value types, such as:
93
+ // stringValue(), booleanValue(), float64Value(), float64ArrayValue(),
94
+ // float32ArrayValue(), int64ArrayValue(), and stringArrayValue().
95
+ ```
96
+
97
+ Or you can make a batch request for multiple join keys:
98
+
99
+ ``` java
100
+ List<GetFeaturesRequestData > requestDataList = new ArrayList<> ();
101
+ requestDataList. add(getFeaturesRequestData);
102
+ GetFeaturesBatchRequest batchRequest = new GetFeaturesBatchRequest (workspaceName, featureServiceName, getFeaturesRequestDataList, RequestConstants . DEFAULT_METADATA_OPTIONS , 5 );
103
+ GetFeaturesBatchResponse batchResponse = tectonClient. getFeaturesBatch(batchRequest);
104
+
105
+ // Same as resp above.
106
+ GetFeaturesResponse sampleResponse = batchResponse. getBatchResponseList(). get(0 );
107
+ ```
108
+
12
109
## Troubleshooting
13
110
14
111
If you have any questions or need help,
0 commit comments