Package: wyvern-ai
WyvernWyvern is a real-time machine learning platform for marketplacesHomepage|Docs|Join Us On SlackWhat is Wyvern?Wyvern is a real-time machine learning platform for marketplaces:Search and Discovery: Wyvern specializes in bringing use cases likerecommendations and rankingsin-house.Empower the Data Team: Wyvern is tailored for your data team to independently build and deploy production-grade machine learning pipelines for the e-commerce and marketplace industry, reducing the engineering involvement in the entire process.Orchestration for ML Pipelines: Wyvern is agnostic to the solutions your pick for your feature sotre, model serving solution, or data warehouse. It automates the process of retrieving data from the feature store and passing data to the model service, as well as logging all the events. It abstracts all the engineering work above away from data scientists, with the goal of enabling data scientists to own the full ML stack, so that they can just focus on defining the request/response schemas of the API, the model, the features the model depends on, the business logic after the model, and finally training the models with the feedback data generated by the ML pipeline.More about why we built Wyvern can be foundhere.Wyvern ArchitectureOverall, Wyvern gives you a framework to quickly define your real-time ML pipeline. There are a couple of important components as you can see in the architecture:Retrieval: Wyvern can connect to and retrieve objects from your search index.Feature Module: Wyvern has the built-in support forfeast, an open source feature store. It also supports connecting to the feature store that you would like to use. Moreover, Wyvern provides interfaces for you to define yourbatch featuresandreal-time featureseasily, with the support of feature grouping, feature sharing, features for composite entities and request based features.Model Module: Wyvern providesthe model interfacethat allows you to define your own model in place or call your model service. It provides an interface to define features that your model depends on easily.Business Logic: Wyvern makes defining your business logic easy after the model inference. For example, if your want to promote a specific brand of tshirt and move it to the top of the ranking result for the "tshirt" query.Observability and Event Logging: All the events in your ML application, including real-time feature, model, business logic, product impression, as well your own custom events, are being automatically logged by Wyvern and data can be piped to your data warehouse. Refer toLogging Eventsfor more information.Training Dataset: Wyvern provides the feature store serving solution (currently integrated only with feast) to serve all data of the historical batch features and the real-time features that are logged in your data warehouse.As Wyvern is open sourced, we will bring in more integrations with different feature stores, model serving solutions, search index for retrieval, observability tools, as well as integrations with more data warehouses.QuickstartInstall Wyvernpip install wyvern-aiCreate Wyvern ProjectOnce Wyvern is installed, run this command to initialize your Wyvern project:wyvern init name_of_your_projectNow that thewyvern inithas set up your initial repository, you should see the following file structure in the generated repository:├── pipelines
│   ├── __init__.py
│   ├── main.py
│   ├── product_ranking
│   │   ├── __init__.py
│   │   ├── models.py
│   │   ├── ranking_pipline.py
│   │   ├── realtime_features.py
│   │   ├── schemas.py
├── feature-store-python
│   ├── features
│   │   ├── feature_store.yaml
│   │   ├── features.py
│   │   ├── main.py
├── .env
└── .gitignoreThe generated template code is anML pipelineexample for ranking products.Run Wyvern ApplicationPre-requisiteRedis serviceWyvern uses redis as its index and online feature store. By default, Wyvern connects to the localhost:6379Your can run this command to install and spin up redis locallywyvern redisRun WyvernNow cd into the repository that was generated and run:wyvern runNow your service runs onhttp://0.0.0.0:5001and the default ranking API schema could be found athttp://0.0.0.0:5001/redoc.Make A RequestAssuming you have 24 products and you would like to rank them. Here's a curl request:curl --location 'http://0.0.0.0:5001/api/v1/ranking' \
--header 'Content-Type: application/json' \
--data '{
    "request_id": "test_request_id",
    "query": {"query": "candle"},
    "candidates": [
        {"product_id": "p1"},
        {"product_id": "p2"},
        {"product_id": "p3"},
        {"product_id": "p4"},
        {"product_id": "p5"},
        {"product_id": "p6"},
        {"product_id": "p7"},
        {"product_id": "p8"},
        {"product_id": "p9"},
        {"product_id": "p10"},
        {"product_id": "p11"},
        {"product_id": "p12"},
        {"product_id": "p13"},
        {"product_id": "p14"},
        {"product_id": "p15"},
        {"product_id": "p16"},
        {"product_id": "p17"},
        {"product_id": "p18"},
        {"product_id": "p19"},
        {"product_id": "p20"},
        {"product_id": "p21"},
        {"product_id": "p22"},
        {"product_id": "p23"},
        {"product_id": "p24"}
    ],
    "user_page_size": 8,
    "user_page": 0,
    "candidate_page_size": 24,
    "candidate_page": 0
}'The request sends 24 products to Wyvern. Wyvern ranks these products and returns the 8 products (in descending order) on the first page ("user_page": 0).You should see a response with the products being ordered descendingly by their ranking score.Click to see a response example{
  "ranked_candidates": [
    {
      "candidate_id": "p9",
      "ranked_score": 43.13991415724884
    },
    {
      "candidate_id": "p18",
      "ranked_score": 42.314880208313376
    },
    {
      "candidate_id": "p17",
      "ranked_score": 41.62010469362527
    },
    {
      "candidate_id": "p3",
      "ranked_score": 40.48391586690772
    },
    {
      "candidate_id": "p19",
      "ranked_score": 39.82504624652922
    },
    {
      "candidate_id": "p24",
      "ranked_score": 39.10042317690844
    },
    {
      "candidate_id": "p11",
      "ranked_score": 38.670359237541945
    },
    {
      "candidate_id": "p21",
      "ranked_score": 37.27313489135458
    }
  ]
}:tada:Congratulations on making your first Wyvern request!!!To learn more about how this ML pipeline is built, check outWyvern ML PipelineTo learn more about Wyvern in general, check out ourdocumentationsMore DocumentationsHow Wyvern ML Pipeline WorksWyvern Feature Engineering