Class ChalkClientImpl

java.lang.Object
ai.chalk.client.ChalkClientImpl
All Implemented Interfaces:
ChalkClient, AutoCloseable

public class ChalkClientImpl extends Object implements ChalkClient
  • Constructor Details

  • Method Details

    • onlineQuery

      public OnlineQueryResult onlineQuery(OnlineQueryParamsComplete params) throws ChalkException
      Description copied from interface: ChalkClient
      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>
      Specified by:
      onlineQuery in interface ChalkClient
      Throws:
      ChalkException
    • ping

      public int ping(int num) throws ChalkException
      Description copied from interface: ChalkClient
      Pings the Chalk engine with num and returns the number echoed by the engine.
      Specified by:
      ping in interface ChalkClient
      Parameters:
      num - the number to send to the engine
      Returns:
      the number echoed by the engine
      Throws:
      ChalkException - if the engine cannot be reached
    • uploadFeatures

      public UploadFeaturesResult uploadFeatures(UploadFeaturesParams params) throws ChalkException
      Description copied from interface: ChalkClient
      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>
      Specified by:
      uploadFeatures in interface ChalkClient
      Throws:
      ChalkException
    • printConfig

      public void printConfig()
      Description copied from interface: ChalkClient
      Prints the current ChalkClient configuration and its sources to stdout.
      Specified by:
      printConfig in interface ChalkClient
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable