shaped 2.0.1__py3-none-any.whl → 2.0.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (341) hide show
  1. shaped/__init__.py +59 -4
  2. shaped/autogen/__init__.py +527 -66
  3. shaped/autogen/api/__init__.py +4 -3
  4. shaped/autogen/api/engine_api.py +1467 -0
  5. shaped/autogen/api/{dataset_api.py → query_api.py} +159 -194
  6. shaped/autogen/api/table_api.py +1494 -0
  7. shaped/autogen/api/{model_management_api.py → view_api.py} +179 -181
  8. shaped/autogen/api_client.py +18 -11
  9. shaped/autogen/configuration.py +22 -9
  10. shaped/autogen/exceptions.py +25 -5
  11. shaped/autogen/models/__init__.py +247 -52
  12. shaped/autogen/models/ai_enrichment_view_config.py +123 -0
  13. shaped/autogen/models/{path.py → algorithm.py} +19 -19
  14. shaped/autogen/models/amplitude_table_config.py +106 -0
  15. shaped/autogen/models/ascending.py +148 -0
  16. shaped/autogen/models/attn_dropout_prob.py +136 -0
  17. shaped/autogen/models/attribute_journey.py +124 -0
  18. shaped/autogen/models/attribute_value.py +178 -0
  19. shaped/autogen/models/autoscaling_config.py +95 -0
  20. shaped/autogen/models/aws_pinpoint_table_config.py +108 -0
  21. shaped/autogen/models/batch_size.py +136 -0
  22. shaped/autogen/models/batch_size1.py +136 -0
  23. shaped/autogen/models/batch_size2.py +136 -0
  24. shaped/autogen/models/big_query_table_config.py +147 -0
  25. shaped/autogen/models/bm25.py +136 -0
  26. shaped/autogen/models/boosted_reorder_step.py +125 -0
  27. shaped/autogen/models/canary_rollout.py +99 -0
  28. shaped/autogen/models/candidate_attributes_retrieve_step.py +113 -0
  29. shaped/autogen/models/candidate_ids_retrieve_step.py +113 -0
  30. shaped/autogen/models/candidate_retrieval_strategy.py +41 -0
  31. shaped/autogen/models/clickhouse_table_config.py +146 -0
  32. shaped/autogen/models/column_order_retrieve_step.py +123 -0
  33. shaped/autogen/models/column_ordering.py +91 -0
  34. shaped/autogen/models/create_table_response.py +87 -0
  35. shaped/autogen/models/create_view_response.py +87 -0
  36. shaped/autogen/models/custom_table_config.py +135 -0
  37. shaped/autogen/models/data_compute_config.py +89 -0
  38. shaped/autogen/models/data_config.py +145 -0
  39. shaped/autogen/models/data_config_interaction_table.py +146 -0
  40. shaped/autogen/models/data_split_config.py +88 -0
  41. shaped/autogen/models/data_split_strategy.py +37 -0
  42. shaped/autogen/models/data_tier.py +37 -0
  43. shaped/autogen/models/default.py +246 -0
  44. shaped/autogen/models/delete_engine_response.py +87 -0
  45. shaped/autogen/models/delete_table_response.py +87 -0
  46. shaped/autogen/models/delete_view_response.py +87 -0
  47. shaped/autogen/models/deployment_config.py +117 -0
  48. shaped/autogen/models/distance_function.py +38 -0
  49. shaped/autogen/models/diversity_reorder_step.py +137 -0
  50. shaped/autogen/models/dropout_rate.py +136 -0
  51. shaped/autogen/models/dynamo_db_table_config.py +160 -0
  52. shaped/autogen/models/dynamo_db_table_config_scan_kwargs_value.py +138 -0
  53. shaped/autogen/models/embedder_batch_size.py +136 -0
  54. shaped/autogen/models/embedding_config.py +93 -0
  55. shaped/autogen/models/embedding_dim.py +136 -0
  56. shaped/autogen/models/embedding_dims.py +136 -0
  57. shaped/autogen/models/embedding_size.py +136 -0
  58. shaped/autogen/models/encoder.py +140 -0
  59. shaped/autogen/models/encoding_pooling_strategy.py +38 -0
  60. shaped/autogen/models/engine.py +109 -0
  61. shaped/autogen/models/engine_config_v2.py +152 -0
  62. shaped/autogen/models/engine_details_response.py +120 -0
  63. shaped/autogen/models/engine_schema.py +113 -0
  64. shaped/autogen/models/engine_schema_user_inner.py +146 -0
  65. shaped/autogen/models/entity_config.py +109 -0
  66. shaped/autogen/models/entity_journey.py +161 -0
  67. shaped/autogen/models/entity_type.py +38 -0
  68. shaped/autogen/models/evaluation_config.py +92 -0
  69. shaped/autogen/models/exploration_reorder_step.py +125 -0
  70. shaped/autogen/models/expression_filter_step.py +106 -0
  71. shaped/autogen/models/factors.py +136 -0
  72. shaped/autogen/models/factors1.py +136 -0
  73. shaped/autogen/models/feature.py +90 -0
  74. shaped/autogen/models/feature_type.py +60 -0
  75. shaped/autogen/models/file_table_config.py +112 -0
  76. shaped/autogen/models/filter_config.py +99 -0
  77. shaped/autogen/models/filter_dataset.py +164 -0
  78. shaped/autogen/models/filter_index_type.py +36 -0
  79. shaped/autogen/models/filter_retrieve_step.py +113 -0
  80. shaped/autogen/models/filter_step_explanation.py +165 -0
  81. shaped/autogen/models/filter_table.py +140 -0
  82. shaped/autogen/models/filter_type.py +134 -0
  83. shaped/autogen/models/global_filter.py +102 -0
  84. shaped/autogen/models/hidden_dropout_prob.py +136 -0
  85. shaped/autogen/models/hidden_size.py +136 -0
  86. shaped/autogen/models/hidden_size1.py +136 -0
  87. shaped/autogen/models/http_problem_response.py +115 -0
  88. shaped/autogen/models/http_validation_error.py +2 -2
  89. shaped/autogen/models/hugging_face_encoder.py +115 -0
  90. shaped/autogen/models/iceberg_table_config.py +154 -0
  91. shaped/autogen/models/index_config.py +101 -0
  92. shaped/autogen/models/inner_entity_id.py +144 -0
  93. shaped/autogen/models/inner_size.py +136 -0
  94. shaped/autogen/models/inner_size1.py +136 -0
  95. shaped/autogen/models/inner_uid.py +144 -0
  96. shaped/autogen/models/interaction_config.py +122 -0
  97. shaped/autogen/models/interaction_pooling_encoder.py +104 -0
  98. shaped/autogen/models/interaction_round_robin_encoder.py +104 -0
  99. shaped/autogen/models/item_attribute_pooling_encoder.py +111 -0
  100. shaped/autogen/models/journey.py +140 -0
  101. shaped/autogen/models/kafka_table_config.py +129 -0
  102. shaped/autogen/models/kinesis_table_config.py +140 -0
  103. shaped/autogen/models/kinesis_table_config_column_schema_value.py +136 -0
  104. shaped/autogen/models/label.py +90 -0
  105. shaped/autogen/models/label_type.py +36 -0
  106. shaped/autogen/models/laplace_smoothing.py +136 -0
  107. shaped/autogen/models/latency_scaling_policy.py +112 -0
  108. shaped/autogen/models/learning_rate.py +136 -0
  109. shaped/autogen/models/learning_rate1.py +136 -0
  110. shaped/autogen/models/learning_rate2.py +136 -0
  111. shaped/autogen/models/learning_rate3.py +136 -0
  112. shaped/autogen/models/lexical_search_mode.py +99 -0
  113. shaped/autogen/models/list_engines_response.py +95 -0
  114. shaped/autogen/models/list_tables_response.py +95 -0
  115. shaped/autogen/models/list_views_response.py +95 -0
  116. shaped/autogen/models/location_inner.py +138 -0
  117. shaped/autogen/models/loss_types.py +37 -0
  118. shaped/autogen/models/lr.py +136 -0
  119. shaped/autogen/models/lr1.py +136 -0
  120. shaped/autogen/models/lr2.py +136 -0
  121. shaped/autogen/models/max_depth.py +136 -0
  122. shaped/autogen/models/max_leaves.py +136 -0
  123. shaped/autogen/models/max_seq_length.py +136 -0
  124. shaped/autogen/models/max_seq_length1.py +136 -0
  125. shaped/autogen/models/max_seq_length2.py +136 -0
  126. shaped/autogen/models/mode.py +134 -0
  127. shaped/autogen/models/mode1.py +136 -0
  128. shaped/autogen/models/mode2.py +150 -0
  129. shaped/autogen/models/models_inner.py +308 -0
  130. shaped/autogen/models/mongo_db_table_config.py +147 -0
  131. shaped/autogen/models/mssql_table_config.py +155 -0
  132. shaped/autogen/models/{my_sql_dataset_config.py → my_sql_table_config.py} +45 -28
  133. shaped/autogen/models/n_epochs.py +136 -0
  134. shaped/autogen/models/n_epochs1.py +136 -0
  135. shaped/autogen/models/n_epochs2.py +136 -0
  136. shaped/autogen/models/n_estimators.py +136 -0
  137. shaped/autogen/models/n_heads.py +136 -0
  138. shaped/autogen/models/n_layers.py +136 -0
  139. shaped/autogen/models/neg_per_positive.py +136 -0
  140. shaped/autogen/models/negative_samples_count.py +136 -0
  141. shaped/autogen/models/ngram_tokenizer.py +103 -0
  142. shaped/autogen/models/no_op_config.py +117 -0
  143. shaped/autogen/models/num_blocks.py +136 -0
  144. shaped/autogen/models/num_heads.py +136 -0
  145. shaped/autogen/models/num_leaves.py +136 -0
  146. shaped/autogen/models/objective.py +40 -0
  147. shaped/autogen/models/objective1.py +134 -0
  148. shaped/autogen/models/online_store_config.py +89 -0
  149. shaped/autogen/models/pagination_config.py +87 -0
  150. shaped/autogen/models/parameter_definition.py +96 -0
  151. shaped/autogen/models/parameters_value.py +240 -0
  152. shaped/autogen/models/passthrough_score.py +104 -0
  153. shaped/autogen/models/personal_filter.py +104 -0
  154. shaped/autogen/models/pipeline_stage_explanation.py +118 -0
  155. shaped/autogen/models/policy.py +134 -0
  156. shaped/autogen/models/pool_fn.py +152 -0
  157. shaped/autogen/models/pooling_function.py +37 -0
  158. shaped/autogen/models/{postgres_dataset_config.py → postgres_table_config.py} +66 -28
  159. shaped/autogen/models/posthog_table_config.py +133 -0
  160. shaped/autogen/models/prebuilt_filter_step.py +113 -0
  161. shaped/autogen/models/precomputed_item_embedding.py +99 -0
  162. shaped/autogen/models/precomputed_user_embedding.py +99 -0
  163. shaped/autogen/models/query.py +136 -0
  164. shaped/autogen/models/query1.py +136 -0
  165. shaped/autogen/models/query_any_of.py +172 -0
  166. shaped/autogen/models/query_config.py +140 -0
  167. shaped/autogen/models/query_definition.py +106 -0
  168. shaped/autogen/models/query_encoder.py +194 -0
  169. shaped/autogen/models/query_explanation.py +201 -0
  170. shaped/autogen/models/query_request.py +121 -0
  171. shaped/autogen/models/query_result.py +113 -0
  172. shaped/autogen/models/query_table_config.py +99 -0
  173. shaped/autogen/models/rank_item_attribute_values_query_config.py +122 -0
  174. shaped/autogen/models/rank_query_config.py +167 -0
  175. shaped/autogen/models/rank_query_config_filter_inner.py +149 -0
  176. shaped/autogen/models/rank_query_config_reorder_inner.py +186 -0
  177. shaped/autogen/models/rank_query_config_retrieve_inner.py +265 -0
  178. shaped/autogen/models/recreate_rollout.py +97 -0
  179. shaped/autogen/models/{redshift_dataset_config.py → redshift_table_config.py} +48 -25
  180. shaped/autogen/models/reference_table_config.py +113 -0
  181. shaped/autogen/models/regularization.py +136 -0
  182. shaped/autogen/models/reorder_inner.py +149 -0
  183. shaped/autogen/models/reorder_step_explanation.py +207 -0
  184. shaped/autogen/models/request.py +378 -0
  185. shaped/autogen/models/request1.py +140 -0
  186. shaped/autogen/models/requests_per_second_scaling_policy.py +112 -0
  187. shaped/autogen/models/resource_config.py +100 -0
  188. shaped/autogen/models/response_get_view_details_views_view_name_get.py +134 -0
  189. shaped/autogen/models/result.py +132 -0
  190. shaped/autogen/models/result_embeddings_value.py +127 -0
  191. shaped/autogen/models/retrieval_scores_value.py +127 -0
  192. shaped/autogen/models/retrieve_inner.py +196 -0
  193. shaped/autogen/models/retrieve_step_explanation.py +172 -0
  194. shaped/autogen/models/retriever.py +196 -0
  195. shaped/autogen/models/retriever1.py +196 -0
  196. shaped/autogen/models/rollout_config.py +91 -0
  197. shaped/autogen/models/rudderstack_table_config.py +106 -0
  198. shaped/autogen/models/sampling_strategy.py +36 -0
  199. shaped/autogen/models/saved_query_info_response.py +103 -0
  200. shaped/autogen/models/saved_query_list_response.py +87 -0
  201. shaped/autogen/models/saved_query_request.py +115 -0
  202. shaped/autogen/models/schema_config.py +117 -0
  203. shaped/autogen/models/score.py +134 -0
  204. shaped/autogen/models/score_ensemble.py +127 -0
  205. shaped/autogen/models/score_ensemble_policy_config.py +165 -0
  206. shaped/autogen/models/score_ensemble_policy_config_policies_inner.py +755 -0
  207. shaped/autogen/models/score_step_explanation.py +224 -0
  208. shaped/autogen/models/search_config.py +105 -0
  209. shaped/autogen/models/segment_table_config.py +106 -0
  210. shaped/autogen/models/sequence_length.py +136 -0
  211. shaped/autogen/models/server_config.py +100 -0
  212. shaped/autogen/models/setup_engine_response.py +87 -0
  213. shaped/autogen/models/shaped_internal_recsys_policies_als_model_policy_als_model_policy_config.py +154 -0
  214. shaped/autogen/models/shaped_internal_recsys_policies_beeformer_model_policy_beeformer_model_policy_beeformer_model_policy_config.py +160 -0
  215. shaped/autogen/models/shaped_internal_recsys_policies_bert_model_policy_bert_model_policy_bert_model_policy_config.py +215 -0
  216. shaped/autogen/models/shaped_internal_recsys_policies_chronological_model_policy_chronological_model_policy_config.py +156 -0
  217. shaped/autogen/models/shaped_internal_recsys_policies_elsa_model_policy_elsa_model_policy_elsa_model_policy_config.py +141 -0
  218. shaped/autogen/models/shaped_internal_recsys_policies_gsasrec_model_policy_gsasrec_model_policy_gsas_rec_model_policy_config.py +211 -0
  219. shaped/autogen/models/shaped_internal_recsys_policies_item2vec_model_policy_item2_vec_model_policy_config.py +140 -0
  220. shaped/autogen/models/shaped_internal_recsys_policies_item_content_similarity_model_policy_item_content_similarity_model_policy_config.py +195 -0
  221. shaped/autogen/models/shaped_internal_recsys_policies_lightgbm_model_policy_lightgbm_model_policy_light_gbm_model_policy_config.py +245 -0
  222. shaped/autogen/models/shaped_internal_recsys_policies_ngram_model_policy_ngram_model_policy_config.py +119 -0
  223. shaped/autogen/models/shaped_internal_recsys_policies_popular_model_policy_popular_model_policy_config.py +161 -0
  224. shaped/autogen/models/shaped_internal_recsys_policies_random_model_policy_random_model_policy_config.py +108 -0
  225. shaped/autogen/models/shaped_internal_recsys_policies_recently_popular_policy_recently_popular_policy_config.py +143 -0
  226. shaped/autogen/models/shaped_internal_recsys_policies_rising_popular_policy_rising_popular_policy_config.py +123 -0
  227. shaped/autogen/models/shaped_internal_recsys_policies_sasrec_model_policy_sasrec_model_policy_sas_rec_model_policy_config.py +230 -0
  228. shaped/autogen/models/shaped_internal_recsys_policies_svd_model_policy_svd_model_policy_config.py +119 -0
  229. shaped/autogen/models/shaped_internal_recsys_policies_two_tower_model_policy_two_tower_model_policy_two_tower_model_policy_config.py +165 -0
  230. shaped/autogen/models/shaped_internal_recsys_policies_user_item_content_similarity_model_policy_user_item_content_similarity_model_policy_config.py +153 -0
  231. shaped/autogen/models/shaped_internal_recsys_policies_widedeep_model_policy_wide_deep_model_policy_config.py +137 -0
  232. shaped/autogen/models/shaped_internal_recsys_policies_xgboost_model_policy_xg_boost_model_policy_config.py +155 -0
  233. shaped/autogen/models/shopify_table_config.py +156 -0
  234. shaped/autogen/models/similarity_retrieve_step.py +123 -0
  235. shaped/autogen/models/{snowflake_dataset_config.py → snowflake_table_config.py} +47 -18
  236. shaped/autogen/models/sql_transform_type.py +37 -0
  237. shaped/autogen/models/sql_view_config.py +111 -0
  238. shaped/autogen/models/stemmer_tokenizer.py +105 -0
  239. shaped/autogen/models/step_explanation.py +137 -0
  240. shaped/autogen/models/steps_inner.py +179 -0
  241. shaped/autogen/models/strategy.py +134 -0
  242. shaped/autogen/models/table.py +102 -0
  243. shaped/autogen/models/table_deployment_type.py +38 -0
  244. shaped/autogen/models/table_insert_arguments.py +87 -0
  245. shaped/autogen/models/table_insert_response.py +87 -0
  246. shaped/autogen/models/text_encoding.py +148 -0
  247. shaped/autogen/models/text_search_retrieve_step.py +121 -0
  248. shaped/autogen/models/time_frequency.py +136 -0
  249. shaped/autogen/models/time_window.py +136 -0
  250. shaped/autogen/models/time_window_in_days.py +154 -0
  251. shaped/autogen/models/tokenizer.py +149 -0
  252. shaped/autogen/models/trained_model_encoder.py +99 -0
  253. shaped/autogen/models/training_compute_config.py +99 -0
  254. shaped/autogen/models/training_config.py +121 -0
  255. shaped/autogen/models/training_config_models_inner.py +540 -0
  256. shaped/autogen/models/training_strategy.py +37 -0
  257. shaped/autogen/models/transform_status.py +41 -0
  258. shaped/autogen/models/trending_mode.py +37 -0
  259. shaped/autogen/models/truncate_filter_step.py +106 -0
  260. shaped/autogen/models/tunable_bool.py +97 -0
  261. shaped/autogen/models/tunable_float.py +118 -0
  262. shaped/autogen/models/tunable_int.py +118 -0
  263. shaped/autogen/models/tunable_int_categorical.py +99 -0
  264. shaped/autogen/models/tunable_string.py +99 -0
  265. shaped/autogen/models/tuning_config.py +89 -0
  266. shaped/autogen/models/type.py +150 -0
  267. shaped/autogen/models/update_table_response.py +87 -0
  268. shaped/autogen/models/update_view_response.py +87 -0
  269. shaped/autogen/models/user_attribute_pooling_encoder.py +124 -0
  270. shaped/autogen/models/user_inner.py +134 -0
  271. shaped/autogen/models/val_split.py +136 -0
  272. shaped/autogen/models/validation_error.py +13 -3
  273. shaped/autogen/models/validation_error_loc_inner.py +150 -0
  274. shaped/autogen/models/value_type.py +7 -5
  275. shaped/autogen/models/vector_search_mode.py +101 -0
  276. shaped/autogen/models/view.py +104 -0
  277. shaped/autogen/models/view_details_ai.py +140 -0
  278. shaped/autogen/models/view_details_ai_schema_value.py +153 -0
  279. shaped/autogen/models/view_details_sql.py +140 -0
  280. shaped/autogen/models/view_status.py +41 -0
  281. shaped/autogen/models/weight_decay.py +136 -0
  282. shaped/autogen/models/whitespace_tokenizer.py +97 -0
  283. shaped/autogen/models/window_size.py +136 -0
  284. shaped/autogen/rest.py +10 -4
  285. shaped/cli/shaped_cli.py +163 -35
  286. shaped/client.py +591 -171
  287. shaped/config_builders.py +705 -0
  288. shaped/query_builder.py +781 -0
  289. {shaped-2.0.1.dist-info → shaped-2.0.4.dist-info}/METADATA +141 -6
  290. shaped-2.0.4.dist-info/RECORD +296 -0
  291. {shaped-2.0.1.dist-info → shaped-2.0.4.dist-info}/WHEEL +1 -1
  292. shaped-2.0.4.dist-info/entry_points.txt +2 -0
  293. shaped/autogen/api/model_inference_api.py +0 -2825
  294. shaped/autogen/models/amplitude_dataset_config.py +0 -96
  295. shaped/autogen/models/aws_pinpoint_dataset_config.py +0 -96
  296. shaped/autogen/models/big_query_dataset_config.py +0 -114
  297. shaped/autogen/models/complement_items_request.py +0 -99
  298. shaped/autogen/models/complement_items_response.py +0 -89
  299. shaped/autogen/models/connectors_inner.py +0 -134
  300. shaped/autogen/models/create_dataset_arguments.py +0 -263
  301. shaped/autogen/models/create_embedding_response.py +0 -87
  302. shaped/autogen/models/create_item_embedding_request.py +0 -89
  303. shaped/autogen/models/create_model_arguments.py +0 -107
  304. shaped/autogen/models/create_model_response.py +0 -87
  305. shaped/autogen/models/create_user_embedding_request.py +0 -89
  306. shaped/autogen/models/custom_dataset_config.py +0 -115
  307. shaped/autogen/models/dataset_config.py +0 -101
  308. shaped/autogen/models/dataset_schema_type.py +0 -47
  309. shaped/autogen/models/datasets_inner.py +0 -91
  310. shaped/autogen/models/delete_model_response.py +0 -87
  311. shaped/autogen/models/fetch_config.py +0 -95
  312. shaped/autogen/models/file_config.py +0 -105
  313. shaped/autogen/models/file_source_config.py +0 -89
  314. shaped/autogen/models/inference_config.py +0 -101
  315. shaped/autogen/models/insert_model_response.py +0 -87
  316. shaped/autogen/models/interaction.py +0 -87
  317. shaped/autogen/models/list_datasets_response.py +0 -95
  318. shaped/autogen/models/list_models_response.py +0 -95
  319. shaped/autogen/models/model_config.py +0 -99
  320. shaped/autogen/models/model_response.py +0 -95
  321. shaped/autogen/models/mongo_db_dataset_config.py +0 -119
  322. shaped/autogen/models/post_rank_request.py +0 -117
  323. shaped/autogen/models/rank_attribute_response.py +0 -89
  324. shaped/autogen/models/rank_grid_attribute_request.py +0 -91
  325. shaped/autogen/models/rank_grid_attribute_request1.py +0 -93
  326. shaped/autogen/models/rank_grid_attribute_response.py +0 -91
  327. shaped/autogen/models/rank_response.py +0 -91
  328. shaped/autogen/models/retrieve_request.py +0 -101
  329. shaped/autogen/models/retrieve_response.py +0 -91
  330. shaped/autogen/models/retriever_top_k_override.py +0 -97
  331. shaped/autogen/models/rudder_stack_dataset_config.py +0 -96
  332. shaped/autogen/models/segment_dataset_config.py +0 -96
  333. shaped/autogen/models/similar_item_request.py +0 -101
  334. shaped/autogen/models/similar_response.py +0 -89
  335. shaped/autogen/models/similar_users_request.py +0 -99
  336. shaped/autogen/models/successful_response.py +0 -87
  337. shaped/autogen/models/view_model_response.py +0 -99
  338. shaped-2.0.1.dist-info/RECORD +0 -73
  339. shaped-2.0.1.dist-info/entry_points.txt +0 -2
  340. {shaped-2.0.1.dist-info → shaped-2.0.4.dist-info}/top_level.txt +0 -0
  341. {shaped-2.0.1.dist-info → shaped-2.0.4.dist-info}/zip-safe +0 -0
@@ -0,0 +1,781 @@
1
+ """
2
+ Fluent query builder for constructing Shaped V2 declarative queries.
3
+ This module provides a fluent API for building RankQueryConfig objects
4
+ that leverage the declarative nature of Shaped's query language.
5
+ """
6
+
7
+ from typing import Any, Dict, List, Optional, TypedDict, Union
8
+
9
+ from shaped.autogen.models.boosted_reorder_step import BoostedReorderStep
10
+ from shaped.autogen.models.candidate_attributes_retrieve_step import (
11
+ CandidateAttributesRetrieveStep,
12
+ )
13
+ from shaped.autogen.models.candidate_ids_retrieve_step import CandidateIdsRetrieveStep
14
+ from shaped.autogen.models.column_order_retrieve_step import ColumnOrderRetrieveStep
15
+ from shaped.autogen.models.diversity_reorder_step import DiversityReorderStep
16
+ from shaped.autogen.models.exploration_reorder_step import ExplorationReorderStep
17
+ from shaped.autogen.models.expression_filter_step import ExpressionFilterStep
18
+ from shaped.autogen.models.filter_retrieve_step import FilterRetrieveStep
19
+ from shaped.autogen.models.passthrough_score import PassthroughScore
20
+ from shaped.autogen.models.prebuilt_filter_step import PrebuiltFilterStep
21
+
22
+ # Import all model classes
23
+ from shaped.autogen.models.rank_query_config import RankQueryConfig
24
+ from shaped.autogen.models.score_ensemble import ScoreEnsemble
25
+ from shaped.autogen.models.similarity_retrieve_step import SimilarityRetrieveStep
26
+ from shaped.autogen.models.text_search_retrieve_step import TextSearchRetrieveStep
27
+ from shaped.autogen.models.truncate_filter_step import TruncateFilterStep
28
+
29
+
30
+ # Type definition for column ordering
31
+ class ColumnOrdering(TypedDict, total=False):
32
+ """Type definition for column ordering in retrieve steps."""
33
+
34
+ name: str
35
+ ascending: Optional[bool]
36
+ nulls_first: Optional[bool]
37
+
38
+
39
+ # Factory functions for creating step objects (no "Step" suffix for cleaner names)
40
+
41
+
42
+ def Passthrough(
43
+ name: Optional[str] = None,
44
+ ) -> PassthroughScore:
45
+ """
46
+ Create a passthrough score.
47
+
48
+ Args:
49
+ name: Optional name for this score.
50
+
51
+ Returns:
52
+ PassthroughScore instance
53
+ """
54
+ return PassthroughScore(
55
+ name=name,
56
+ )
57
+
58
+
59
+ def ColumnOrder(
60
+ columns: List[Union[Dict[str, Any], ColumnOrdering]],
61
+ limit: int = 100,
62
+ where: Optional[str] = None,
63
+ name: Optional[str] = None,
64
+ ) -> ColumnOrderRetrieveStep:
65
+ """
66
+ Create a column order retrieve step.
67
+
68
+ Args:
69
+ columns: List of column orderings (dicts with 'name' and optionally
70
+ 'ascending', 'nulls_first').
71
+ limit: Maximum number of candidates to retrieve.
72
+ where: Optional DuckDB filter expression.
73
+ name: Optional name for this retrieve step.
74
+
75
+ Returns:
76
+ ColumnOrderRetrieveStep instance
77
+ """
78
+ return ColumnOrderRetrieveStep(
79
+ columns=columns,
80
+ limit=limit,
81
+ where=where,
82
+ name=name,
83
+ )
84
+
85
+
86
+ def TextSearch(
87
+ input_text_query: str,
88
+ mode: Dict[str, Any],
89
+ limit: int = 100,
90
+ where: Optional[str] = None,
91
+ name: Optional[str] = None,
92
+ ) -> TextSearchRetrieveStep:
93
+ """
94
+ Create a text search retrieve step.
95
+
96
+ Args:
97
+ input_text_query: Text query parameter or value.
98
+ mode: Search mode dict with 'type' ('lexical' or 'vector') and
99
+ mode-specific fields.
100
+ limit: Maximum number of candidates to retrieve.
101
+ where: Optional DuckDB filter expression.
102
+ name: Optional name for this retrieve step.
103
+
104
+ Returns:
105
+ TextSearchRetrieveStep instance
106
+ """
107
+ return TextSearchRetrieveStep(
108
+ input_text_query=input_text_query,
109
+ mode=mode,
110
+ limit=limit,
111
+ where=where,
112
+ name=name,
113
+ )
114
+
115
+
116
+ def Similarity(
117
+ embedding_ref: str,
118
+ query_encoder: Dict[str, Any],
119
+ limit: int = 100,
120
+ where: Optional[str] = None,
121
+ name: Optional[str] = None,
122
+ ) -> SimilarityRetrieveStep:
123
+ """
124
+ Create a similarity retrieve step.
125
+
126
+ Args:
127
+ embedding_ref: Name of the embedding to use.
128
+ query_encoder: Encoder configuration dict.
129
+ limit: Maximum number of candidates to retrieve.
130
+ where: Optional DuckDB filter expression.
131
+ name: Optional name for this retrieve step.
132
+
133
+ Returns:
134
+ SimilarityRetrieveStep instance
135
+ """
136
+ return SimilarityRetrieveStep(
137
+ embedding_ref=embedding_ref,
138
+ query_encoder=query_encoder,
139
+ limit=limit,
140
+ where=where,
141
+ name=name,
142
+ )
143
+
144
+
145
+ def CandidateIds(
146
+ item_ids: List[str],
147
+ limit: Optional[int] = None,
148
+ name: Optional[str] = None,
149
+ ) -> CandidateIdsRetrieveStep:
150
+ """
151
+ Create a candidate IDs retrieve step.
152
+
153
+ Args:
154
+ item_ids: List of entity IDs to retrieve.
155
+ limit: Maximum number of IDs to retrieve (defaults to length of item_ids).
156
+ name: Optional name for this retrieve step.
157
+
158
+ Returns:
159
+ CandidateIdsRetrieveStep instance
160
+ """
161
+ return CandidateIdsRetrieveStep(
162
+ item_ids=item_ids,
163
+ limit=limit,
164
+ name=name,
165
+ )
166
+
167
+
168
+ def CandidateAttributes(
169
+ item_attributes: List[Dict[str, Any]],
170
+ limit: Optional[int] = None,
171
+ name: Optional[str] = None,
172
+ ) -> CandidateAttributesRetrieveStep:
173
+ """
174
+ Create a candidate attributes retrieve step.
175
+
176
+ Args:
177
+ item_attributes: List of item attribute dictionaries.
178
+ limit: Maximum number of items to retrieve.
179
+ name: Optional name for this retrieve step.
180
+
181
+ Returns:
182
+ CandidateAttributesRetrieveStep instance
183
+ """
184
+ return CandidateAttributesRetrieveStep(
185
+ item_attributes=item_attributes,
186
+ limit=limit,
187
+ name=name,
188
+ )
189
+
190
+
191
+ def Filter(
192
+ where: Optional[str] = None,
193
+ limit: int = 100,
194
+ name: Optional[str] = None,
195
+ ) -> FilterRetrieveStep:
196
+ """
197
+ Create a filter retrieve step (filtering without ordering).
198
+
199
+ Args:
200
+ where: Optional DuckDB filter expression.
201
+ limit: Maximum number of candidates to retrieve.
202
+ name: Optional name for this retrieve step.
203
+
204
+ Returns:
205
+ FilterRetrieveStep instance
206
+ """
207
+ return FilterRetrieveStep(
208
+ where=where,
209
+ limit=limit,
210
+ name=name,
211
+ )
212
+
213
+
214
+ def Expression(
215
+ expression: str,
216
+ name: Optional[str] = None,
217
+ ) -> ExpressionFilterStep:
218
+ """
219
+ Create an expression filter step.
220
+
221
+ Args:
222
+ expression: DuckDB filter expression.
223
+ name: Optional name for this filter step.
224
+
225
+ Returns:
226
+ ExpressionFilterStep instance
227
+ """
228
+ return ExpressionFilterStep(
229
+ expression=expression,
230
+ name=name,
231
+ )
232
+
233
+
234
+ def Truncate(
235
+ max_length: int = 500,
236
+ name: Optional[str] = None,
237
+ ) -> TruncateFilterStep:
238
+ """
239
+ Create a truncate filter step.
240
+
241
+ Args:
242
+ max_length: Maximum number of items to keep after truncation.
243
+ name: Optional name for this filter step.
244
+
245
+ Returns:
246
+ TruncateFilterStep instance
247
+ """
248
+ return TruncateFilterStep(
249
+ max_length=max_length,
250
+ name=name,
251
+ )
252
+
253
+
254
+ def Prebuilt(
255
+ filter_ref: str,
256
+ input_user_id: Optional[str] = None,
257
+ name: Optional[str] = None,
258
+ ) -> PrebuiltFilterStep:
259
+ """
260
+ Create a prebuilt filter step.
261
+
262
+ Args:
263
+ filter_ref: Reference to a prebuilt filter (e.g., ref:data.filters:name).
264
+ input_user_id: User ID for personal filters. Required for personal,
265
+ omitted for global filters.
266
+ name: Optional name for this filter step.
267
+
268
+ Returns:
269
+ PrebuiltFilterStep instance
270
+ """
271
+ return PrebuiltFilterStep(
272
+ filter_ref=filter_ref,
273
+ input_user_id=input_user_id,
274
+ name=name,
275
+ )
276
+
277
+
278
+ def ensemble(
279
+ value_model: str,
280
+ input_user_id: Optional[str] = None,
281
+ input_user_features: Optional[Dict[str, Any]] = None,
282
+ input_interactions_item_ids: Optional[List[str]] = None,
283
+ name: Optional[str] = None,
284
+ **kwargs: Any,
285
+ ) -> ScoreEnsemble:
286
+ """
287
+ Create a score ensemble step.
288
+
289
+ Args:
290
+ value_model: Name of the value model to use for scoring.
291
+ input_user_id: Optional user ID for personalization.
292
+ input_user_features: Optional dictionary of user features.
293
+ input_interactions_item_ids: Optional list of item IDs from user interactions.
294
+ name: Optional name for this score step.
295
+ **kwargs: Additional keyword arguments for backward compatibility.
296
+
297
+ Returns:
298
+ ScoreEnsemble instance
299
+
300
+ Example:
301
+ >>> ensemble("lightgbm", input_user_id="user123")
302
+ >>> ensemble("xgboost", name="xgboost_scorer")
303
+ """
304
+ # Handle the case where parameters are passed in the options dictionary
305
+ if not input_user_id and "input_user_id" in kwargs:
306
+ input_user_id = kwargs.pop("input_user_id")
307
+ if not input_user_features and "input_user_features" in kwargs:
308
+ input_user_features = kwargs.pop("input_user_features")
309
+ if not input_interactions_item_ids and "input_interactions_item_ids" in kwargs:
310
+ input_interactions_item_ids = kwargs.pop("input_interactions_item_ids")
311
+ if not name and "name" in kwargs:
312
+ name = kwargs.pop("name")
313
+
314
+ # Create the config dictionary
315
+ config: Dict[str, Any] = {
316
+ "value_model": value_model,
317
+ }
318
+
319
+ # Add optional parameters if provided
320
+ if input_user_id is not None:
321
+ config["input_user_id"] = input_user_id
322
+ if input_user_features is not None:
323
+ config["input_user_features"] = input_user_features
324
+ if input_interactions_item_ids is not None:
325
+ config["input_interactions_item_ids"] = input_interactions_item_ids
326
+ if name is not None:
327
+ config["name"] = name
328
+
329
+ # Add any additional parameters from kwargs (for backward compatibility)
330
+ config.update(kwargs)
331
+
332
+ return ScoreEnsemble(**config)
333
+
334
+
335
+ def passthrough(name: Optional[str] = None) -> PassthroughScore:
336
+ """
337
+ Create a passthrough score step that doesn't modify the scores.
338
+
339
+ Args:
340
+ name: Optional name for this score step.
341
+
342
+ Returns:
343
+ PassthroughScore instance
344
+
345
+ Example:
346
+ >>> passthrough()
347
+ >>> passthrough(name="noop_scorer")
348
+ """
349
+ config: Dict[str, Any] = {
350
+ "type": "passthrough",
351
+ }
352
+ if name is not None:
353
+ config["name"] = name
354
+ return PassthroughScore(**config)
355
+
356
+
357
+ def Boosted(
358
+ retriever: Dict[str, Any],
359
+ strength: float = 0.5,
360
+ name: Optional[str] = None,
361
+ ) -> BoostedReorderStep:
362
+ """
363
+ Create a boosted reorder step.
364
+
365
+ Args:
366
+ retriever: Retrieve step to use as source for boosting.
367
+ strength: Boost strength (0.0-1.0).
368
+ name: Optional name for this reorder step.
369
+
370
+ Returns:
371
+ BoostedReorderStep instance
372
+ """
373
+ return BoostedReorderStep(
374
+ retriever=retriever,
375
+ strength=strength,
376
+ name=name,
377
+ )
378
+
379
+
380
+ def Exploration(
381
+ retriever: Dict[str, Any],
382
+ strength: float = 0.5,
383
+ name: Optional[str] = None,
384
+ ) -> ExplorationReorderStep:
385
+ """
386
+ Create an exploration reorder step.
387
+
388
+ Args:
389
+ retriever: Retrieve step to use as source for exploration.
390
+ strength: Exploration strength (0.0-1.0).
391
+ name: Optional name for this reorder step.
392
+
393
+ Returns:
394
+ ExplorationReorderStep instance
395
+ """
396
+ return ExplorationReorderStep(
397
+ retriever=retriever,
398
+ strength=strength,
399
+ name=name,
400
+ )
401
+
402
+
403
+ def Diversity(
404
+ diversity_attributes: Optional[Union[List[str], str]] = None,
405
+ limit: int = 100,
406
+ name: Optional[str] = None,
407
+ strength: float = 0.5,
408
+ diversity_lookback_window: int = 30,
409
+ diversity_lookforward_window: int = 30,
410
+ text_encoding_embedding_ref: Optional[str] = None,
411
+ **kwargs,
412
+ ) -> DiversityReorderStep:
413
+ """
414
+ Create a diversity reorder step.
415
+
416
+ Args:
417
+ diversity_attributes: List of attribute names to use for diversification.
418
+ limit: Maximum number of items to return after diversification.
419
+ name: Optional name for this reorder step.
420
+ strength: Strength of the diversity effect (0.0 to 1.0).
421
+ diversity_lookback_window: Number of previous items to consider for diversity.
422
+ diversity_lookforward_window: Number of next items to consider for diversity.
423
+ text_encoding_embedding_ref: Reference to text encoding embedding.
424
+ **kwargs: Additional keyword arguments for backward compatibility.
425
+
426
+ Returns:
427
+ DiversityReorderStep instance
428
+ """
429
+ # Handle the case where diversity_attributes is passed as a single string
430
+ if isinstance(diversity_attributes, str):
431
+ diversity_attributes = [diversity_attributes]
432
+
433
+ # Handle the case where diversity_attributes is not provided but is in kwargs
434
+ if diversity_attributes is None:
435
+ if "diversity_attribute" in kwargs:
436
+ diversity_attributes = [kwargs.pop("diversity_attribute")]
437
+ elif "diversityAttributes" in kwargs:
438
+ diversity_attributes = kwargs.pop("diversityAttributes")
439
+ if isinstance(diversity_attributes, str):
440
+ diversity_attributes = [diversity_attributes]
441
+
442
+ # Create the config dictionary
443
+ config: Dict[str, Any] = {
444
+ "diversity_attributes": diversity_attributes or [],
445
+ "limit": limit,
446
+ "strength": strength,
447
+ "diversity_lookback_window": diversity_lookback_window,
448
+ "diversity_lookforward_window": diversity_lookforward_window,
449
+ }
450
+
451
+ # Add text_encoding_embedding_ref if provided
452
+ if text_encoding_embedding_ref is not None:
453
+ config["text_encoding_embedding_ref"] = text_encoding_embedding_ref
454
+
455
+ # Add name if provided
456
+ if name is not None:
457
+ config["name"] = name
458
+
459
+ # Add any additional parameters from kwargs (for backward compatibility)
460
+ config.update(kwargs)
461
+
462
+ return DiversityReorderStep(**config)
463
+
464
+
465
+ def _get_step_type(step: Any) -> Optional[str]:
466
+ """Extract step type from step object or dict."""
467
+ if isinstance(step, dict):
468
+ return step.get("type")
469
+ if hasattr(step, "type"):
470
+ return getattr(step, "type")
471
+ return None
472
+
473
+
474
+ class RankQueryBuilder:
475
+ """
476
+ Fluent builder for constructing RankQueryConfig queries.
477
+
478
+ Example:
479
+ from shaped import RankQueryBuilder, ColumnOrder, TextSearch, Filter, Expression, Ensemble, Diversity
480
+
481
+ query = (RankQueryBuilder()
482
+ .from_entity('item')
483
+ .retrieve(
484
+ ColumnOrder([{'name': 'popularity', 'ascending': False}], limit=1000),
485
+ TextSearch('laptop', mode={'type': 'vector', 'text_embedding_ref': 'text_emb'}),
486
+ Filter(where='category == "electronics"', limit=500)
487
+ )
488
+ .filter(Expression('price < 1000'))
489
+ .score(Ensemble('lightgbm', input_user_id='$parameters.userId'))
490
+ .reorder(Diversity(diversity_attributes=['category']))
491
+ .limit(50)
492
+ .columns(['item_id', 'title', 'price'])
493
+ .build())
494
+ """
495
+
496
+ def __init__(self):
497
+ self._retrieve_steps: List[Union[Dict[str, Any], Any]] = []
498
+ self._filter_steps: List[Union[Dict[str, Any], Any]] = []
499
+ self._score_config: Optional[Union[Dict[str, Any], Any]] = None
500
+ self._reorder_steps: List[Union[Dict[str, Any], Any]] = []
501
+ self._from_entity: Optional[str] = None
502
+ self._limit: Optional[int] = None
503
+ self._columns: Optional[List[str]] = None
504
+ self._embeddings: Optional[List[str]] = None
505
+
506
+ def from_entity(self, entity: str) -> "RankQueryBuilder":
507
+ """
508
+ Set the entity type to rank (item or user).
509
+
510
+ Args:
511
+ entity: Entity type, either 'item', 'user', or 'item_attribute'.
512
+
513
+ Returns:
514
+ Self for method chaining.
515
+ """
516
+ if entity not in ["item", "user", "item_attribute"]:
517
+ raise ValueError(
518
+ f"Entity must be 'item', 'user', or 'item_attribute', got '{entity}'"
519
+ )
520
+ self._from_entity = entity
521
+ return self
522
+
523
+ def retrieve(
524
+ self,
525
+ *steps: Union[
526
+ ColumnOrderRetrieveStep,
527
+ TextSearchRetrieveStep,
528
+ SimilarityRetrieveStep,
529
+ FilterRetrieveStep,
530
+ CandidateIdsRetrieveStep,
531
+ CandidateAttributesRetrieveStep,
532
+ Dict[str, Any],
533
+ ],
534
+ ) -> "RankQueryBuilder":
535
+ """
536
+ Add one or more retrieve steps.
537
+
538
+ Args:
539
+ *steps: Retrieve step objects (ColumnOrder, TextSearch, Similarity,
540
+ Filter, CandidateIds, CandidateAttributes) or dicts.
541
+
542
+ Returns:
543
+ Self for method chaining.
544
+ """
545
+ valid_types = {
546
+ "column_order",
547
+ "text_search",
548
+ "similarity",
549
+ "filter",
550
+ "candidate_ids",
551
+ "candidate_attributes",
552
+ }
553
+ for step in steps:
554
+ step_type = _get_step_type(step)
555
+ if step_type is None:
556
+ raise ValueError(
557
+ f"Invalid retrieve step: missing 'type' field. "
558
+ f"Expected one of: {', '.join(sorted(valid_types))}"
559
+ )
560
+ if step_type not in valid_types:
561
+ raise ValueError(
562
+ f"Invalid retrieve step type: '{step_type}'. "
563
+ f"Expected one of: {', '.join(sorted(valid_types))}"
564
+ )
565
+ self._retrieve_steps.append(step)
566
+ return self
567
+
568
+ def filter(
569
+ self,
570
+ *steps: Union[
571
+ ExpressionFilterStep,
572
+ TruncateFilterStep,
573
+ PrebuiltFilterStep,
574
+ Dict[str, Any],
575
+ ],
576
+ ) -> "RankQueryBuilder":
577
+ """
578
+ Add one or more filter steps.
579
+
580
+ Args:
581
+ *steps: Filter step objects (Expression, Truncate, Prebuilt) or dicts.
582
+
583
+ Returns:
584
+ Self for method chaining.
585
+
586
+ Examples:
587
+ .filter(Expression('price < 1000'))
588
+ .filter(Truncate(max_length=100))
589
+ .filter(Prebuilt('ref:data.filters:my_filter', input_user_id='$parameters.userId'))
590
+ .filter(Expression('price > 100'), Truncate(max_length=500), Prebuilt('ref:data.filters:global'))
591
+ """
592
+ valid_types = {"expression", "truncate", "prebuilt"}
593
+
594
+ for step in steps:
595
+ step_type = _get_step_type(step)
596
+ if step_type is None:
597
+ raise ValueError(
598
+ f"Invalid filter step: missing 'type' field. "
599
+ f"Expected one of: {', '.join(sorted(valid_types))}"
600
+ )
601
+ if step_type not in valid_types:
602
+ raise ValueError(
603
+ f"Invalid filter step type: '{step_type}'. "
604
+ f"Expected one of: {', '.join(sorted(valid_types))}"
605
+ )
606
+ self._filter_steps.append(step)
607
+ return self
608
+
609
+ def score(
610
+ self,
611
+ config: Union[ScoreEnsemble, PassthroughScore, Dict[str, Any]],
612
+ ) -> "RankQueryBuilder":
613
+ """
614
+ Set the score configuration.
615
+
616
+ Args:
617
+ config: Score configuration (Ensemble, Passthrough) or dict.
618
+
619
+ Returns:
620
+ Self for method chaining.
621
+ """
622
+ valid_types = {"score_ensemble", "passthrough"}
623
+ step_type = _get_step_type(config)
624
+ if step_type is None:
625
+ raise ValueError(
626
+ f"Invalid score config: missing 'type' field. "
627
+ f"Expected one of: {', '.join(sorted(valid_types))}"
628
+ )
629
+ if step_type not in valid_types:
630
+ raise ValueError(
631
+ f"Invalid score config type: '{step_type}'. "
632
+ f"Expected one of: {', '.join(sorted(valid_types))}"
633
+ )
634
+ self._score_config = config
635
+ return self
636
+
637
+ def reorder(
638
+ self,
639
+ *steps: Union[
640
+ DiversityReorderStep,
641
+ BoostedReorderStep,
642
+ ExplorationReorderStep,
643
+ Dict[str, Any],
644
+ ],
645
+ ) -> "RankQueryBuilder":
646
+ """
647
+ Add one or more reorder steps.
648
+
649
+ Args:
650
+ *steps: Reorder step objects (Diversity, Boosted, Exploration) or dicts.
651
+
652
+ Returns:
653
+ Self for method chaining.
654
+ """
655
+ valid_types = {"diversity", "boosted", "exploration"}
656
+ for step in steps:
657
+ step_type = _get_step_type(step)
658
+ if step_type is None:
659
+ raise ValueError(
660
+ f"Invalid reorder step: missing 'type' field. "
661
+ f"Expected one of: {', '.join(sorted(valid_types))}"
662
+ )
663
+ if step_type not in valid_types:
664
+ raise ValueError(
665
+ f"Invalid reorder step type: '{step_type}'. "
666
+ f"Expected one of: {', '.join(sorted(valid_types))}"
667
+ )
668
+ self._reorder_steps.append(step)
669
+ return self
670
+
671
+ def limit(self, limit: int) -> "RankQueryBuilder":
672
+ """
673
+ Set the maximum number of entities to return.
674
+
675
+ Args:
676
+ limit: Maximum number of entities.
677
+
678
+ Returns:
679
+ Self for method chaining.
680
+ """
681
+ self._limit = limit
682
+ return self
683
+
684
+ def columns(self, columns: List[str]) -> "RankQueryBuilder":
685
+ """
686
+ Set the list of column names to include in results.
687
+
688
+ Args:
689
+ columns: List of column names.
690
+
691
+ Returns:
692
+ Self for method chaining.
693
+ """
694
+ self._columns = columns
695
+ return self
696
+
697
+ def embeddings(self, embeddings: List[str]) -> "RankQueryBuilder":
698
+ """
699
+ Set the list of embedding names to include in results.
700
+
701
+ Args:
702
+ embeddings: List of embedding names.
703
+
704
+ Returns:
705
+ Self for method chaining.
706
+ """
707
+ self._embeddings = embeddings
708
+ return self
709
+
710
+ def build(self) -> Union[RankQueryConfig, Dict[str, Any]]:
711
+ """
712
+ Build the RankQueryConfig object.
713
+
714
+ Returns:
715
+ RankQueryConfig instance if models are available, otherwise a dict.
716
+ """
717
+ config: Dict[str, Any] = {"type": "rank"}
718
+
719
+ if self._from_entity is not None:
720
+ config["from"] = self._from_entity
721
+
722
+ if self._retrieve_steps:
723
+ # Convert steps to dicts if they're model instances
724
+ retrieve_list = []
725
+ for step in self._retrieve_steps:
726
+ if isinstance(step, dict):
727
+ retrieve_list.append(step)
728
+ elif hasattr(step, "model_dump"):
729
+ retrieve_list.append(step.model_dump(by_alias=True))
730
+ else:
731
+ retrieve_list.append(step)
732
+ config["retrieve"] = retrieve_list
733
+
734
+ if self._filter_steps:
735
+ filter_list = []
736
+ for step in self._filter_steps:
737
+ if isinstance(step, dict):
738
+ filter_list.append(step)
739
+ elif hasattr(step, "model_dump"):
740
+ filter_list.append(step.model_dump(by_alias=True))
741
+ else:
742
+ filter_list.append(step)
743
+ config["filter"] = filter_list
744
+
745
+ if self._score_config is not None:
746
+ if isinstance(self._score_config, dict):
747
+ config["score"] = self._score_config
748
+ elif hasattr(self._score_config, "model_dump"):
749
+ config["score"] = self._score_config.model_dump(by_alias=True)
750
+ else:
751
+ config["score"] = self._score_config
752
+
753
+ if self._reorder_steps:
754
+ reorder_list = []
755
+ for step in self._reorder_steps:
756
+ if isinstance(step, dict):
757
+ reorder_list.append(step)
758
+ elif hasattr(step, "model_dump"):
759
+ reorder_list.append(step.model_dump(by_alias=True))
760
+ else:
761
+ reorder_list.append(step)
762
+ config["reorder"] = reorder_list
763
+
764
+ if self._limit is not None:
765
+ config["limit"] = self._limit
766
+
767
+ if self._columns is not None:
768
+ config["columns"] = self._columns
769
+
770
+ if self._embeddings is not None:
771
+ config["embeddings"] = self._embeddings
772
+
773
+ # If models are available, convert to proper model instance.
774
+ if RankQueryConfig is not None:
775
+ try:
776
+ return RankQueryConfig(**config)
777
+ except Exception:
778
+ # Fallback to dict if conversion fails
779
+ return config
780
+
781
+ return config