Interface ChalkClient

All Superinterfaces:
AutoCloseable
All Known Implementing Classes:
ChalkClientImpl, GRPCClient

public interface ChalkClient extends AutoCloseable
  • Method Details

    • builder

      static ChalkClient.Builder builder()
      Creates a new ChalkClient builder that can be used to create a ChalkClient instance with custom configuration.

      Example:

          
          client = ChalkClient.builder()
                  .withEnvironmentId("socmc8beyufew")
                  .withClientId("98wrasfg7dge7wdasg709")
                  .withClientSecret("h23lkj4h23lkj4z9s78fg908as7fkjh324klj23")
                  .build();
          
       
      Returns:
      a new ChalkClient builder
    • create

      static ChalkClient create() throws ChalkException

      Creates a new default ChalkClient instance. The default ChalkClient instance is configured with config variables sourced as such:

      For each variable, we take the first non-empty value, in order, from the following sources:

      1. The value of the config's corresponding environment variable (see ConfigEnvVars).

      2. The value in the project root's 'chalk.yaml' or 'chalk.yml' file.

      To override the settings above with custom configuration, use builder().

      Returns:
      a new default ChalkClient instance
      Throws:
      ChalkException
    • createGrpc

      static ChalkClient createGrpc() throws ChalkException

      Creates a new ChalkClient instance that uses gRPC for communication. The gRPC ChalkClient instance is configured with config variables sourced the same way as the default ChalkClient instance.

      Returns:
      a new ChalkClient instance that uses gRPC
      Throws:
      ChalkException
    • onlineQuery

      OnlineQuery computes features values using online resolvers.

      See OnlineQueryParams for more details on the parameters.

      Example usage for bulk queries:

               {@code
               OnlineQueryParamsComplete params = OnlineQueryParams.builder()
                   .withInput("user.id", Arrays.asList(1, 2, 3))
                   .withOutputs("user.email", "user.transactions")
                   .build();
      
               try (OnlineQueryResult result = client.onlineQuery(params)) {
                   // do something with the result
               }
           </pre>
       </p>
      
       <p>
       Example usage for single-row queries using SingleRowInput:
       <pre>
               {@code
               var singleRow = new OnlineQueryParams.SingleRowInput()
                   .withInput("user.id", 123)
                   .withInput("user.email", "test@example.com")
                   .withInput("user.favorite_foods", Arrays.asList("pizza", "pasta"));
      
               OnlineQueryParamsComplete params = OnlineQueryParams.builder()
                   .withInput(singleRow)
                   .withOutputs("user.credit_score", "user.transactions")
                   .build();
      
               try (OnlineQueryResult result = client.onlineQuery(params)) {
                   // do something with the result
               }
           </pre>
       </p>
      
       @return {@link OnlineQueryResult }
       @throws ChalkException
       @see <a href="https://docs.chalk.ai/docs/query-basics">query basics</a>
      Throws:
      ChalkException
    • uploadFeatures

      UploadFeatures synchronously persists feature values to the online store and offline store.

      See UploadFeaturesParams for more details on the parameters.

      Example usage:

               {@code
               var userIds = Arrays.asList("777", "888", "999");
               var scoreList = Arrays.asList(600, 700, 800);
               UploadFeaturesParams params = UploadFeaturesParams.builder()
                   .withInputs(Map.of("user.id", userIds,"user.credit_score", scoreList))
                   .withInput(Features.user.email, List.of("user1@email.com", "user2@email.com", "user3@email.com"))
                   .build();
               UploadFeaturesResult res = client.uploadFeatures(params);
               if (client.uploadFeatures(params).getErrors().size() > 0) {
                   throw new Exception("upload failed");
               }
      
           </pre>
       </p>
      Throws:
      ChalkException
    • printConfig

      void printConfig()
      Prints the current ChalkClient configuration and its sources to stdout.