Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(wren-ai-service): Refactor Semantics Description Pipeline with Output Filtering and Request Model Updates #1272

Merged
merged 4 commits into from
Feb 7, 2025

Conversation

paopa
Copy link
Member

@paopa paopa commented Feb 6, 2025

This PR introduces improvements to the Semantics Description pipeline by adding output filtering capabilities and restructuring request handling.

Key Changes

  • Added new output function in semantics description pipeline to filter and validate columns
  • Replaced Input model with GenerateRequest model in semantics description service
  • Updated pipeline final step from normalize to output
  • Added comprehensive tests for output filtering functionality
  • Updated response handling to use output instead of normalize

Technical Details

  • Introduced column filtering logic to prevent hallucinated columns
  • Simplified request handling in the generate endpoint using model_dump()
  • Added test cases covering various scenarios including:
    • Normal operation without hallucination
    • Handling of hallucinated columns
    • Edge cases with no valid columns
    • Batch processing
    • Concurrent updates

Testing

  • Added new test file test_semantics_enrichment.py
  • Updated existing tests to reflect new output structure
  • All tests passing ✅

Try it on the Web endpoint

  • Endpoint: POST /v1/semantics-descriptions
  • Request Body
{
  "selected_models": [
    "olist_customers_dataset"
  ],
  "user_prompt": "remove the customer_ prefix",
  "mdl": "{\"schema\":\"public\",\"catalog\":\"wrenai\",\"sampleDataFolder\":\"gs://wren-data-sample/4\",\"models\":[{\"name\":\"olist_customers_dataset\",\"columns\":[{\"name\":\"customer_id\",\"type\":\"VARCHAR\",\"isCalculated\":false,\"notNull\":false,\"expression\":\"\",\"properties\":{\"description\":null,\"displayName\":\"customer_id\"}},{\"name\":\"customer_unique_id\",\"type\":\"VARCHAR\",\"isCalculated\":false,\"notNull\":false,\"expression\":\"\",\"properties\":{\"description\":\"Unique id of the customer\",\"displayName\":\"customer_unique_id\"}},{\"name\":\"customer_zip_code_prefix\",\"type\":\"VARCHAR\",\"isCalculated\":false,\"notNull\":false,\"expression\":\"\",\"properties\":{\"description\":\"First 5 digits of customer zip code\",\"displayName\":\"customer_zip_code_prefix\"}},{\"name\":\"customer_city\",\"type\":\"VARCHAR\",\"isCalculated\":false,\"notNull\":false,\"expression\":\"\",\"properties\":{\"description\":\"Name of the city where the customer is located\",\"displayName\":\"customer_city\"}},{\"name\":\"customer_state\",\"type\":\"VARCHAR\",\"isCalculated\":false,\"notNull\":false,\"expression\":\"\",\"properties\":{\"description\":\"Name of the state where the customer is located\",\"displayName\":\"customer_state\"}},{\"name\":\"olist_orders_dataset\",\"type\":\"olist_orders_dataset\",\"properties\":null,\"relationship\":\"Olist_orders_datasetCustomer_idOlist_customers_datasetCustomer_id\",\"isCalculated\":false,\"notNull\":false},{\"name\":\"olist_geolocation_dataset\",\"type\":\"olist_geolocation_dataset\",\"properties\":null,\"relationship\":\"Olist_geolocation_datasetGeolocation_zip_code_prefixOlist_customers_datasetCustomer_zip_code_prefix\",\"isCalculated\":false,\"notNull\":false}],\"tableReference\":{\"catalog\":\"memory\",\"schema\":\"main\",\"table\":\"olist_customers_dataset\"},\"refSql\":null,\"cached\":false,\"refreshTime\":null,\"properties\":{\"displayName\":\"customers\"},\"primaryKey\":\"customer_id\"},{\"name\":\"olist_geolocation_dataset\",\"columns\":[{\"name\":\"geolocation_zip_code_prefix\",\"type\":\"VARCHAR\",\"isCalculated\":false,\"notNull\":false,\"expression\":\"\",\"properties\":{\"displayName\":\"geolocation_zip_code_prefix\",\"description\":\"First 5 digits of zip code\"}},{\"name\":\"geolocation_lat\",\"type\":\"DOUBLE\",\"isCalculated\":false,\"notNull\":false,\"expression\":\"\",\"properties\":{\"displayName\":\"geolocation_lat\",\"description\":\"The coordinations for the locations latitude\"}},{\"name\":\"geolocation_lng\",\"type\":\"DOUBLE\",\"isCalculated\":false,\"notNull\":false,\"expression\":\"\",\"properties\":{\"displayName\":\"geolocation_lng\",\"description\":\"The coordinations for the locations longitude\"}},{\"name\":\"geolocation_city\",\"type\":\"VARCHAR\",\"isCalculated\":false,\"notNull\":false,\"expression\":\"\",\"properties\":{\"displayName\":\"geolocation_city\",\"description\":\"The city name of the geolocation\"}},{\"name\":\"geolocation_state\",\"type\":\"VARCHAR\",\"isCalculated\":false,\"notNull\":false,\"expression\":\"\",\"properties\":{\"displayName\":\"geolocation_state\",\"description\":\"The state of the geolocation\"}},{\"name\":\"olist_customers_dataset\",\"type\":\"olist_customers_dataset\",\"properties\":null,\"relationship\":\"Olist_geolocation_datasetGeolocation_zip_code_prefixOlist_customers_datasetCustomer_zip_code_prefix\",\"isCalculated\":false,\"notNull\":false},{\"name\":\"olist_sellers_dataset\",\"type\":\"olist_sellers_dataset\",\"properties\":null,\"relationship\":\"Olist_geolocation_datasetGeolocation_zip_code_prefixOlist_sellers_datasetSeller_zip_code_prefix\",\"isCalculated\":false,\"notNull\":false}],\"tableReference\":{\"catalog\":\"memory\",\"schema\":\"main\",\"table\":\"olist_geolocation_dataset\"},\"refSql\":null,\"cached\":false,\"refreshTime\":null,\"properties\":{\"displayName\":\"geolocation\",\"description\":\"This table contains detailed information about Brazilian zip codes and their corresponding latitude and longitude coordinates. It can be used to plot maps, calculate distances between sellers and customers, and perform geographic analysis.\"},\"primaryKey\":\"\"},{\"name\":\"olist_orders_dataset\",\"columns\":[{\"name\":\"order_id\",\"type\":\"VARCHAR\",\"isCalculated\":false,\"notNull\":false,\"expression\":\"\",\"properties\":{\"description\":\"Unique identifier for the specific order\",\"displayName\":\"order_id\"}},{\"name\":\"customer_id\",\"type\":\"VARCHAR\",\"isCalculated\":false,\"notNull\":false,\"expression\":\"\",\"properties\":{\"description\":\"Unique identifier for the customer who placed the order.\",\"displayName\":\"customer_id\"}},{\"name\":\"order_status\",\"type\":\"VARCHAR\",\"isCalculated\":false,\"notNull\":false,\"expression\":\"\",\"properties\":{\"description\":\"Current status of the order (e.g., delivered, shipped, canceled).\",\"displayName\":\"order_status\"}},{\"name\":\"order_purchase_timestamp\",\"type\":\"TIMESTAMP\",\"isCalculated\":false,\"notNull\":false,\"expression\":\"\",\"properties\":{\"description\":\"Date and time when the order was placed by the customer.\",\"displayName\":\"order_purchase_timestamp\"}},{\"name\":\"order_approved_at\",\"type\":\"TIMESTAMP\",\"isCalculated\":false,\"notNull\":false,\"expression\":\"\",\"properties\":{\"description\":\"Date and time when the order was approved for processing.\",\"displayName\":\"order_approved_at\"}},{\"name\":\"order_delivered_carrier_date\",\"type\":\"TIMESTAMP\",\"isCalculated\":false,\"notNull\":false,\"expression\":\"\",\"properties\":{\"description\":\"Date when the order was handed over to the carrier or freight forwarder for delivery.\",\"displayName\":\"order_delivered_carrier_date\"}},{\"name\":\"order_delivered_customer_date\",\"type\":\"TIMESTAMP\",\"isCalculated\":false,\"notNull\":false,\"expression\":\"\",\"properties\":{\"description\":\"Date when the order was delivered to the customer.\",\"displayName\":\"order_delivered_customer_date\"}},{\"name\":\"order_estimated_delivery_date\",\"type\":\"TIMESTAMP\",\"isCalculated\":false,\"notNull\":false,\"expression\":\"\",\"properties\":{\"description\":\"Expected delivery date based on the initial estimate.\",\"displayName\":\"order_estimated_delivery_date\"}},{\"name\":\"olist_customers_dataset\",\"type\":\"olist_customers_dataset\",\"properties\":null,\"relationship\":\"Olist_orders_datasetCustomer_idOlist_customers_datasetCustomer_id\",\"isCalculated\":false,\"notNull\":false},{\"name\":\"olist_order_items_dataset\",\"type\":\"olist_order_items_dataset\",\"properties\":null,\"relationship\":\"Olist_orders_datasetOrder_idOlist_order_items_datasetOrder_id\",\"isCalculated\":false,\"notNull\":false},{\"name\":\"olist_order_reviews_dataset\",\"type\":\"olist_order_reviews_dataset\",\"properties\":null,\"relationship\":\"Olist_orders_datasetOrder_idOlist_order_reviews_datasetOrder_id\",\"isCalculated\":false,\"notNull\":false},{\"name\":\"olist_order_payments_dataset\",\"type\":\"olist_order_payments_dataset\",\"properties\":null,\"relationship\":\"Olist_orders_datasetOrder_idOlist_order_payments_datasetOrder_id\",\"isCalculated\":false,\"notNull\":false}],\"tableReference\":{\"catalog\":\"memory\",\"schema\":\"main\",\"table\":\"olist_orders_dataset\"},\"refSql\":null,\"cached\":false,\"refreshTime\":null,\"properties\":{\"displayName\":\"orders\",\"description\":\"This table contains detailed information about customer orders, including timestamps for various stages of the order process (approval, shipping, delivery), as well as the order status and customer identification. It helps track the lifecycle of an order from purchase to delivery.\"},\"primaryKey\":\"order_id\"},{\"name\":\"olist_order_items_dataset\",\"columns\":[{\"name\":\"order_id\",\"type\":\"VARCHAR\",\"isCalculated\":false,\"notNull\":false,\"expression\":\"\",\"properties\":{\"description\":\"Unique identifier for the order across the platform\",\"displayName\":\"order_id\"}},{\"name\":\"order_item_id\",\"type\":\"BIGINT\",\"isCalculated\":false,\"notNull\":false,\"expression\":\"\",\"properties\":{\"description\":\"Unique identifier for each item within a specific order\",\"displayName\":\"order_item_id\"}},{\"name\":\"product_id\",\"type\":\"VARCHAR\",\"isCalculated\":false,\"notNull\":false,\"expression\":\"\",\"properties\":{\"description\":\"Unique identifier for the product sold in the order.\",\"displayName\":\"product_id\"}},{\"name\":\"seller_id\",\"type\":\"VARCHAR\",\"isCalculated\":false,\"notNull\":false,\"expression\":\"\",\"properties\":{\"description\":\"Unique identifier of the seller who fulfilled the order item.\",\"displayName\":\"seller_id\"}},{\"name\":\"shipping_limit_date\",\"type\":\"TIMESTAMP\",\"isCalculated\":false,\"notNull\":false,\"expression\":\"\",\"properties\":{\"description\":\"Deadline for the order item to be shipped by the seller.\",\"displayName\":\"shipping_limit_date\"}},{\"name\":\"price\",\"type\":\"DOUBLE\",\"isCalculated\":false,\"notNull\":false,\"expression\":\"\",\"properties\":{\"description\":\"Price of the individual item within the order\",\"displayName\":\"price\"}},{\"name\":\"freight_value\",\"type\":\"DOUBLE\",\"isCalculated\":false,\"notNull\":false,\"expression\":\"\",\"properties\":{\"description\":\"Cost of shipping associated with the specific order item\",\"displayName\":\"freight_value\"}},{\"name\":\"olist_orders_dataset\",\"type\":\"olist_orders_dataset\",\"properties\":null,\"relationship\":\"Olist_orders_datasetOrder_idOlist_order_items_datasetOrder_id\",\"isCalculated\":false,\"notNull\":false},{\"name\":\"olist_products_dataset\",\"type\":\"olist_products_dataset\",\"properties\":null,\"relationship\":\"Olist_order_items_datasetProduct_idOlist_products_datasetProduct_id\",\"isCalculated\":false,\"notNull\":false},{\"name\":\"olist_sellers_dataset\",\"type\":\"olist_sellers_dataset\",\"properties\":null,\"relationship\":\"Olist_order_items_datasetSeller_idOlist_sellers_datasetSeller_id\",\"isCalculated\":false,\"notNull\":false}],\"tableReference\":{\"catalog\":\"memory\",\"schema\":\"main\",\"table\":\"olist_order_items_dataset\"},\"refSql\":null,\"cached\":false,\"refreshTime\":null,\"properties\":{\"displayName\":\"order items\",\"description\":\"This table contains the information related to a specific order containing its shipping cost, products, cost, number of order items, and the seller.\"},\"primaryKey\":\"order_item_id\"},{\"name\":\"olist_order_payments_dataset\",\"columns\":[{\"name\":\"order_id\",\"type\":\"VARCHAR\",\"isCalculated\":false,\"notNull\":false,\"expression\":\"\",\"properties\":{\"description\":\"Unique identifier for the order associated with the payment.\",\"displayName\":\"order_id\"}},{\"name\":\"payment_sequential\",\"type\":\"BIGINT\",\"isCalculated\":false,\"notNull\":false,\"expression\":\"\",\"properties\":{\"description\":\"Sequence number for tracking multiple payments within the same order.\",\"displayName\":\"payment_sequential\"}},{\"name\":\"payment_type\",\"type\":\"VARCHAR\",\"isCalculated\":false,\"notNull\":false,\"expression\":\"\",\"properties\":{\"description\":\"Method used for the payment, such as credit card, debit, or voucher.\",\"displayName\":\"payment_type\"}},{\"name\":\"payment_installments\",\"type\":\"BIGINT\",\"isCalculated\":false,\"notNull\":false,\"expression\":\"\",\"properties\":{\"description\":\"Number of installments the payment is divided into for the order.\",\"displayName\":\"payment_installments\"}},{\"name\":\"payment_value\",\"type\":\"DOUBLE\",\"isCalculated\":false,\"notNull\":false,\"expression\":\"\",\"properties\":{\"description\":\"Total amount paid in the specific transaction.\",\"displayName\":\"payment_value\"}},{\"name\":\"olist_orders_dataset\",\"type\":\"olist_orders_dataset\",\"properties\":null,\"relationship\":\"Olist_orders_datasetOrder_idOlist_order_payments_datasetOrder_id\",\"isCalculated\":false,\"notNull\":false}],\"tableReference\":{\"catalog\":\"memory\",\"schema\":\"main\",\"table\":\"olist_order_payments_dataset\"},\"refSql\":null,\"cached\":false,\"refreshTime\":null,\"properties\":{\"displayName\":\"order payments\",\"description\":\"This table contains information about payment details for each order, including payment methods, amounts, installment plans, and payment sequences, helping to track how orders were paid and processed within the e-commerce platform.\"},\"primaryKey\":\"order_id\"},{\"name\":\"olist_order_reviews_dataset\",\"columns\":[{\"name\":\"review_id\",\"type\":\"VARCHAR\",\"isCalculated\":false,\"notNull\":false,\"expression\":\"\",\"properties\":{\"description\":\"Unique identifier for the specific review entry.\",\"displayName\":\"review_id\"}},{\"name\":\"order_id\",\"type\":\"VARCHAR\",\"isCalculated\":false,\"notNull\":false,\"expression\":\"\",\"properties\":{\"description\":\"Unique identifier linking the review to the corresponding order.\",\"displayName\":\"order_id\"}},{\"name\":\"review_score\",\"type\":\"BIGINT\",\"isCalculated\":false,\"notNull\":false,\"expression\":\"\",\"properties\":{\"description\":\"Numeric rating given by the customer, typically ranging from 1 (worst) to 5 (best).\",\"displayName\":\"review_score\"}},{\"name\":\"review_comment_title\",\"type\":\"VARCHAR\",\"isCalculated\":false,\"notNull\":false,\"expression\":\"\",\"properties\":{\"description\":\"Summary or title of the customer's review\",\"displayName\":\"review_comment_title\"}},{\"name\":\"review_comment_message\",\"type\":\"VARCHAR\",\"isCalculated\":false,\"notNull\":false,\"expression\":\"\",\"properties\":{\"description\":\"Detailed feedback or comments provided by the customer regarding the order.\",\"displayName\":\"review_comment_message\"}},{\"name\":\"review_creation_date\",\"type\":\"TIMESTAMP\",\"isCalculated\":false,\"notNull\":false,\"expression\":\"\",\"properties\":{\"description\":\"Date and time when the customer initially submitted the review.\",\"displayName\":\"review_creation_date\"}},{\"name\":\"review_answer_timestamp\",\"type\":\"TIMESTAMP\",\"isCalculated\":false,\"notNull\":false,\"expression\":\"\",\"properties\":{\"description\":\"Date and time when the review was responded to by the seller\",\"displayName\":\"review_answer_timestamp\"}},{\"name\":\"olist_orders_dataset\",\"type\":\"olist_orders_dataset\",\"properties\":null,\"relationship\":\"Olist_orders_datasetOrder_idOlist_order_reviews_datasetOrder_id\",\"isCalculated\":false,\"notNull\":false}],\"tableReference\":{\"catalog\":\"memory\",\"schema\":\"main\",\"table\":\"olist_order_reviews_dataset\"},\"refSql\":null,\"cached\":false,\"refreshTime\":null,\"properties\":{\"displayName\":\"order reviews\",\"description\":\"This table contains customer reviews for each order, including feedback comments, ratings, and timestamps for when the review was submitted and responded to. It helps track customer satisfaction and review management on the e-commerce platform.\"},\"primaryKey\":\"review_id\"},{\"name\":\"olist_products_dataset\",\"columns\":[{\"name\":\"product_id\",\"type\":\"VARCHAR\",\"isCalculated\":false,\"notNull\":false,\"expression\":\"\",\"properties\":{\"description\":\"Unique identifier for the product\",\"displayName\":\"product_id\"}},{\"name\":\"product_category_name\",\"type\":\"VARCHAR\",\"isCalculated\":false,\"notNull\":false,\"expression\":\"\",\"properties\":{\"description\":\"Name of the product category to which the item belongs.\",\"displayName\":\"product_category_name\"}},{\"name\":\"product_name_lenght\",\"type\":\"BIGINT\",\"isCalculated\":false,\"notNull\":false,\"expression\":\"\",\"properties\":{\"description\":\"Length of the product name in characters\",\"displayName\":\"product_name_lenght\"}},{\"name\":\"product_description_lenght\",\"type\":\"BIGINT\",\"isCalculated\":false,\"notNull\":false,\"expression\":\"\",\"properties\":{\"description\":\"Length of the product description in characters.\",\"displayName\":\"product_description_lenght\"}},{\"name\":\"product_photos_qty\",\"type\":\"BIGINT\",\"isCalculated\":false,\"notNull\":false,\"expression\":\"\",\"properties\":{\"description\":\"Number of photos available for the product\",\"displayName\":\"product_photos_qty\"}},{\"name\":\"product_weight_g\",\"type\":\"BIGINT\",\"isCalculated\":false,\"notNull\":false,\"expression\":\"\",\"properties\":{\"description\":\"Weight of the product in grams\",\"displayName\":\"product_weight_g\"}},{\"name\":\"product_length_cm\",\"type\":\"BIGINT\",\"isCalculated\":false,\"notNull\":false,\"expression\":\"\",\"properties\":{\"description\":\"Length of the product in centimeters\",\"displayName\":\"product_length_cm\"}},{\"name\":\"product_height_cm\",\"type\":\"BIGINT\",\"isCalculated\":false,\"notNull\":false,\"expression\":\"\",\"properties\":{\"description\":\"Height of the product in centimeters.\",\"displayName\":\"product_height_cm\"}},{\"name\":\"product_width_cm\",\"type\":\"BIGINT\",\"isCalculated\":false,\"notNull\":false,\"expression\":\"\",\"properties\":{\"description\":\"Width of the product in centimeters\",\"displayName\":\"product_width_cm\"}},{\"name\":\"olist_order_items_dataset\",\"type\":\"olist_order_items_dataset\",\"properties\":null,\"relationship\":\"Olist_order_items_datasetProduct_idOlist_products_datasetProduct_id\",\"isCalculated\":false,\"notNull\":false},{\"name\":\"product_category_name_translation\",\"type\":\"product_category_name_translation\",\"properties\":null,\"relationship\":\"Product_category_name_translationProduct_category_nameOlist_products_datasetProduct_category_name\",\"isCalculated\":false,\"notNull\":false}],\"tableReference\":{\"catalog\":\"memory\",\"schema\":\"main\",\"table\":\"olist_products_dataset\"},\"refSql\":null,\"cached\":false,\"refreshTime\":null,\"properties\":{\"displayName\":\"products\",\"description\":\"This table provides detailed information about products, including their category, dimensions, weight, description length, and the number of photos. This helps in managing product details and enhancing the shopping experience on the e-commerce platform.\"},\"primaryKey\":\"product_id\"},{\"name\":\"olist_sellers_dataset\",\"columns\":[{\"name\":\"seller_id\",\"type\":\"VARCHAR\",\"isCalculated\":false,\"notNull\":false,\"expression\":\"\",\"properties\":{\"description\":\"Unique identifier for the seller on the platform\",\"displayName\":\"seller_id\"}},{\"name\":\"seller_zip_code_prefix\",\"type\":\"VARCHAR\",\"isCalculated\":false,\"notNull\":false,\"expression\":\"\",\"properties\":{\"description\":\"First 5 digits of seller zip code\",\"displayName\":\"seller_zip_code_prefix\"}},{\"name\":\"seller_city\",\"type\":\"VARCHAR\",\"isCalculated\":false,\"notNull\":false,\"expression\":\"\",\"properties\":{\"description\":\"The Brazilian city where the seller is located\",\"displayName\":\"seller_city\"}},{\"name\":\"seller_state\",\"type\":\"VARCHAR\",\"isCalculated\":false,\"notNull\":false,\"expression\":\"\",\"properties\":{\"description\":\"The Brazilian state where the seller is located\",\"displayName\":\"seller_state\"}},{\"name\":\"olist_order_items_dataset\",\"type\":\"olist_order_items_dataset\",\"properties\":null,\"relationship\":\"Olist_order_items_datasetSeller_idOlist_sellers_datasetSeller_id\",\"isCalculated\":false,\"notNull\":false},{\"name\":\"olist_geolocation_dataset\",\"type\":\"olist_geolocation_dataset\",\"properties\":null,\"relationship\":\"Olist_geolocation_datasetGeolocation_zip_code_prefixOlist_sellers_datasetSeller_zip_code_prefix\",\"isCalculated\":false,\"notNull\":false}],\"tableReference\":{\"catalog\":\"memory\",\"schema\":\"main\",\"table\":\"olist_sellers_dataset\"},\"refSql\":null,\"cached\":false,\"refreshTime\":null,\"properties\":{\"displayName\":\"sellers\",\"description\":\"This table includes data about the sellers that fulfilled orders made. Use it to find the seller location and to identify which seller fulfilled each product.\"},\"primaryKey\":\"\"},{\"name\":\"product_category_name_translation\",\"columns\":[{\"name\":\"product_category_name\",\"type\":\"VARCHAR\",\"isCalculated\":false,\"notNull\":false,\"expression\":\"\",\"properties\":{\"description\":\"Original name of the product category in Portuguese.\",\"displayName\":\"product_category_name\"}},{\"name\":\"product_category_name_english\",\"type\":\"VARCHAR\",\"isCalculated\":false,\"notNull\":false,\"expression\":\"\",\"properties\":{\"description\":\"Translated name of the product category in English.\",\"displayName\":\"product_category_name_english\"}},{\"name\":\"olist_products_dataset\",\"type\":\"olist_products_dataset\",\"properties\":null,\"relationship\":\"Product_category_name_translationProduct_category_nameOlist_products_datasetProduct_category_name\",\"isCalculated\":false,\"notNull\":false}],\"tableReference\":{\"catalog\":\"memory\",\"schema\":\"main\",\"table\":\"product_category_name_translation\"},\"refSql\":null,\"cached\":false,\"refreshTime\":null,\"properties\":{\"displayName\":\"product category name translation\",\"description\":\"This table contains translations of product categories from Portuguese to English.\"},\"primaryKey\":\"product_category_name\"}],\"relationships\":[{\"name\":\"Olist_orders_datasetCustomer_idOlist_customers_datasetCustomer_id\",\"models\":[\"olist_orders_dataset\",\"olist_customers_dataset\"],\"joinType\":\"MANY_TO_ONE\",\"condition\":\"\\\"olist_orders_dataset\\\".customer_id = \\\"olist_customers_dataset\\\".customer_id\",\"properties\":{}},{\"name\":\"Olist_orders_datasetOrder_idOlist_order_items_datasetOrder_id\",\"models\":[\"olist_orders_dataset\",\"olist_order_items_dataset\"],\"joinType\":\"ONE_TO_MANY\",\"condition\":\"\\\"olist_orders_dataset\\\".order_id = \\\"olist_order_items_dataset\\\".order_id\",\"properties\":{}},{\"name\":\"Olist_orders_datasetOrder_idOlist_order_reviews_datasetOrder_id\",\"models\":[\"olist_orders_dataset\",\"olist_order_reviews_dataset\"],\"joinType\":\"ONE_TO_MANY\",\"condition\":\"\\\"olist_orders_dataset\\\".order_id = \\\"olist_order_reviews_dataset\\\".order_id\",\"properties\":{}},{\"name\":\"Olist_orders_datasetOrder_idOlist_order_payments_datasetOrder_id\",\"models\":[\"olist_orders_dataset\",\"olist_order_payments_dataset\"],\"joinType\":\"ONE_TO_MANY\",\"condition\":\"\\\"olist_orders_dataset\\\".order_id = \\\"olist_order_payments_dataset\\\".order_id\",\"properties\":{}},{\"name\":\"Olist_order_items_datasetProduct_idOlist_products_datasetProduct_id\",\"models\":[\"olist_order_items_dataset\",\"olist_products_dataset\"],\"joinType\":\"MANY_TO_ONE\",\"condition\":\"\\\"olist_order_items_dataset\\\".product_id = \\\"olist_products_dataset\\\".product_id\",\"properties\":{}},{\"name\":\"Olist_order_items_datasetSeller_idOlist_sellers_datasetSeller_id\",\"models\":[\"olist_order_items_dataset\",\"olist_sellers_dataset\"],\"joinType\":\"MANY_TO_ONE\",\"condition\":\"\\\"olist_order_items_dataset\\\".seller_id = \\\"olist_sellers_dataset\\\".seller_id\",\"properties\":{}},{\"name\":\"Olist_geolocation_datasetGeolocation_zip_code_prefixOlist_customers_datasetCustomer_zip_code_prefix\",\"models\":[\"olist_geolocation_dataset\",\"olist_customers_dataset\"],\"joinType\":\"ONE_TO_MANY\",\"condition\":\"\\\"olist_geolocation_dataset\\\".geolocation_zip_code_prefix = \\\"olist_customers_dataset\\\".customer_zip_code_prefix\",\"properties\":{}},{\"name\":\"Olist_geolocation_datasetGeolocation_zip_code_prefixOlist_sellers_datasetSeller_zip_code_prefix\",\"models\":[\"olist_geolocation_dataset\",\"olist_sellers_dataset\"],\"joinType\":\"ONE_TO_MANY\",\"condition\":\"\\\"olist_geolocation_dataset\\\".geolocation_zip_code_prefix = \\\"olist_sellers_dataset\\\".seller_zip_code_prefix\",\"properties\":{}},{\"name\":\"Product_category_name_translationProduct_category_nameOlist_products_datasetProduct_category_name\",\"models\":[\"product_category_name_translation\",\"olist_products_dataset\"],\"joinType\":\"ONE_TO_MANY\",\"condition\":\"\\\"product_category_name_translation\\\".product_category_name = \\\"olist_products_dataset\\\".product_category_name\",\"properties\":{}}],\"views\":[]}",
  "project_id": "string",
  "configuration": {
    "language": "English",
    "timezone": {
      "name": "UTC",
      "utc_offset": ""
    }
  }
}

Impact

These changes improve the reliability of the semantics description pipeline by:

  • Preventing hallucinated columns from appearing in the output
  • Making request handling more maintainable
  • Providing better validation of output data

Summary by CodeRabbit

  • New Features

    • Introduced a refined approach for generating semantic descriptions with enhanced filtering to ensure that only valid data columns are included.
    • Streamlined the request handling by consolidating input parameters into a single, unified structure for improved clarity and efficiency.
  • Tests

    • Expanded test coverage to validate the new output processing and input handling, ensuring robust behavior across different data scenarios.

@paopa paopa added module/ai-service ai-service related ci/ai-service ai-service related labels Feb 6, 2025
Copy link
Contributor

coderabbitai bot commented Feb 6, 2025

Walkthrough

The changes update the semantics description processing pipeline. A new output function is added to filter and restructure normalized model data using picked model details, and the pipeline’s final step is updated from "normalize" to "output". The web layer now creates a GenerateRequest from a post request using model_dump(), streamlining request handling. Additionally, the Input class was removed in favor of GenerateRequest in the service layer, and corresponding tests were updated to validate the new flow and response key change.

Changes

File(s) Change Summary
wren-ai-service/src/pipelines/.../semantics_description.py Added new output(normalize, picked_models) function to filter and restructure data; updated _final attribute from "normalize" to "output" to change pipeline control flow.
wren-ai-service/src/web/v1/routers/semantics_description.py Modified the generate function to create a GenerateRequest using model_dump() from PostRequest, consolidating request parameters.
wren-ai-service/src/web/v1/services/semantics_description.py Removed the Input class and introduced GenerateRequest; updated method signatures (e.g., generate, _handle_exception, _chunking) to reflect the new request type and response structure.
wren-ai-service/tests/pytest/pipelines/generation/test_semantics_enrichment.py Added tests to validate the output function behavior under scenarios with and without hallucinated columns.
wren-ai-service/tests/pytest/services/test_semantics_description.py Updated tests to use GenerateRequest instead of Input and to assert the response key change from "normalize" to "output".

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Router
    participant Service
    participant Pipeline
    Client->>Router: HTTP Request (PostRequest)
    Router->>Router: Convert PostRequest to GenerateRequest using model_dump()
    Router->>Service: Invoke generate(generate_request)
    Service->>Pipeline: Process data through output(normalize, picked_models)
    Pipeline-->>Service: Return filtered model data (output)
    Service-->>Router: Return response with output key
    Router-->>Client: HTTP Response (PostResponse)
Loading

Poem

I hopped through lines of shifting code,
With models picked on my winding road,
Output now shines with columns true,
Tests confirm the path anew,
A bunny’s cheer for changes bestowed!

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
wren-ai-service/tests/pytest/pipelines/generation/test_semantics_enrichment.py (1)

48-67: Consider adding more edge cases.

While the current test covers the case where all columns are hallucinated, consider adding tests for:

  • Empty input models
  • Models with mixed valid and invalid column types
  • Models with special characters in column names
wren-ai-service/src/pipelines/generation/semantics_description.py (1)

91-104: Consider optimizing the filtering logic.

The current implementation creates multiple intermediate dictionaries. Consider using a more memory-efficient approach for large datasets.

-    models = {model["name"]: model for model in picked_models}
-
-    return {
-        name: {**data, "columns": _filter(data["columns"], models[name]["columns"])}
-        for name, data in normalize.items()
-        if name in models
-    }
+    models = {model["name"]: set(col["name"] for col in model["columns"]) 
+             for model in picked_models}
+    
+    return {
+        name: {**data, "columns": [
+            col for col in data["columns"] 
+            if col["name"] in models.get(name, set())
+        ]}
+        for name, data in normalize.items()
+        if name in models
+    }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 937d694 and 8d8cc13.

📒 Files selected for processing (5)
  • wren-ai-service/src/pipelines/generation/semantics_description.py (2 hunks)
  • wren-ai-service/src/web/v1/routers/semantics_description.py (1 hunks)
  • wren-ai-service/src/web/v1/services/semantics_description.py (3 hunks)
  • wren-ai-service/tests/pytest/pipelines/generation/test_semantics_enrichment.py (1 hunks)
  • wren-ai-service/tests/pytest/services/test_semantics_description.py (11 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: pytest
  • GitHub Check: pytest
🔇 Additional comments (11)
wren-ai-service/tests/pytest/pipelines/generation/test_semantics_enrichment.py (2)

4-24: LGTM! Well-structured test for the base case.

The test effectively validates the output function's behavior when no hallucinated columns are present.


26-46: LGTM! Good test coverage for hallucination filtering.

The test properly verifies that hallucinated columns (marked with $) are filtered out while preserving valid columns.

wren-ai-service/src/web/v1/services/semantics_description.py (3)

35-35: LGTM! Type annotation improvement.

The type annotation Dict[str, self.Resource] is more precise than the previous version.


50-57: LGTM! Well-structured request model.

The GenerateRequest model clearly defines all required fields and includes optional configuration.


87-98: Consider adding validation for column names.

The code processes column names but doesn't validate their format. Consider adding validation to ensure column names don't contain special characters that could cause issues.

wren-ai-service/src/web/v1/routers/semantics_description.py (1)

114-116: LGTM! Clean request object creation.

Using model_dump() for request creation is a cleaner approach than manual parameter passing.

wren-ai-service/src/pipelines/generation/semantics_description.py (1)

218-218: LGTM! Pipeline step update.

Updating the final step to "output" aligns with the new filtering functionality.

wren-ai-service/tests/pytest/services/test_semantics_description.py (4)

13-14: LGTM! Mock response structure updated to match pipeline changes.

The mock response structure has been correctly updated to use "output" instead of "normalize", aligning with the pipeline's final step update.


31-36: LGTM! Request model consistently updated across all test cases.

All test cases have been properly updated to use GenerateRequest instead of Input while maintaining the same request structure and parameters.

Also applies to: 57-62, 79-84, 135-140, 171-176, 194-199, 223-228


143-146: LGTM! Batch processing mock responses updated correctly.

The mock responses for batch processing have been properly updated to use the new "output" structure while maintaining the test's logical integrity.


233-237: LGTM! Concurrent test mock response structure updated.

The delayed_response function has been correctly updated to use the new "output" structure while preserving the concurrent testing logic.

@paopa paopa changed the title [DONT MERGE] feat(wren-ai-service): Refactor Semantics Description Pipeline with Output Filtering and Request Model Updates feat(wren-ai-service): Refactor Semantics Description Pipeline with Output Filtering and Request Model Updates Feb 7, 2025
@paopa paopa requested a review from cyyeh February 7, 2025 02:34
Copy link
Member

@cyyeh cyyeh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@paopa paopa merged commit d7b1aa1 into main Feb 7, 2025
10 of 13 checks passed
@paopa paopa deleted the feat/filter-hallucination-name-out branch February 7, 2025 02:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci/ai-service ai-service related module/ai-service ai-service related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants