Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

Latest commit

 

History

History
68 lines (52 loc) · 3.46 KB

business_logic.mdx

File metadata and controls

68 lines (52 loc) · 3.46 KB
title description icon
Business Logic
briefcase

Sometimes you want to override what the model spits out for either business initiatives or some other reasons. Wyvern's business logic is the layer to to overrule something in the model. Business logic layer allows you to further tune the results based on a deliberate set of heuristics

For example, one important business logic use case in ranking is boosting and burying product. Sometimes, there’s one particular product that you want to promote or demote from your ranking list. For instance, if a product contains NSFW (Not Safe For Work) content, wyvern offers you the ability to demote or remove the product from the result even though this product has a good ranking score returned from the model.

Another example - if your analysis shows that having more different brands showing up in the same page would increase the conversion - the diversity of brands matters. On the other hand, having products from the same brand next to each other makes conversion worse. In a case like this to improve the diversity of the product brands, you could easily implement business logic that reorder your page so that products from the same brand are not adjacent to each other.

How It Works

BusinessLogicPipeline is the representation of a sequeance chain of business logics. Within the BusinessLogicPipeline, you can chain many BusinessLogicComponent one after another. BusinessLogicPipeline steps through this series of business logic components and returns the final output

The input to the BusinessLogicPipeline is BusinessLogicRequest. The output of each business logic component is passed as an input to the next business logic component.

Build a BusinessLogicPipeline

class SearchBusinessLogicPipeline(
    BusinessLogicPipeline[Product, ProductRankingRequest],
):
    def __init__(self):
        super().__init__(
            CandleBoostingBusinessLogicComponent(),
            AlwaysBoostWaxSealProduct(),
            BuryBlockListProducts(),
            name="search_business_logic_pipeline",
        )

search_business_logic_pipeline = SearchBusinessLogicPipeline()

In this example, we're building a SearchBusinessLogicPipeline, which your marketplace might use to do the following sequentially:

  1. first Boost candle products
  2. then boost wax seal products
  3. finally bury products in your blocklist.

The business logic's target entity type is Product. ProductRankingRequest is exactly the same request of your ML pipeline.

Now let's look at how a BusinessLogic component AlwaysBoostWaxSealProduct is built:

class AlwaysBoostWaxSealProduct(
    BoostingBusinessLogicComponent[
        Product,
        ProductSearchRankingRequest,
    ],
):
    async def execute(
        self,
        input: BusinessLogicRequest[
            Product,
            ProductSearchRankingRequest,
        ],
        **kwargs,
    ) -> List[ScoredCandidate[Product]]:
        return self.boost(input.scored_candidates, entity_keys={"7"}, boost=100)

The input of this BusinessLogicComponent, AlwaysBoostWaxSealProduct, is BusinessLogicRequest, same as the input of BusinessLogicPipeline, SearchBusinessLogicPipeline.