5 From machine learning to databases: applications of Wasm

 

This chapter covers

  • WASI as a collection of standardized interfaces
  • Machine learning inference in Wasm
  • Applying the ONNX format
  • Running Wasm within databases

Up until now, we have undertaken much of the heavy lifting ourselves. We began the book without even using Wasm components, implementing our own lifting and lowering for the String type. Even after transitioning to Wasm components, we continued to create our own interfaces and hosts to serve as the backbone of our applications. This approach is not ideal for server-side development with Wasm. Instead, we should leverage out-of-the-box hosts and pre-written interfaces—unless, of course, we are developing a very specific application.

In this chapter, we will start utilizing standardized interfaces. Specifically, we will explore how to use the wasi:nn (for neural networks) interface to perform machine learning (ML) with Wasm and we will discuss a separate use case for Wasm running inside a database to power user-defined functions.

5.1 WebAssembly Standard interfaces

5.2 Machine learning with Wasm

5.2.1 Using wasi-nn

5.3 Running Wasm inside databases

5.3.1 Making Wasm UDFs

5.3.2 Getting Wasm into SQL

5.3.3 Running Wasm UDFs in libSQL

5.4 Improving our example project with wasi nn

5.4.1 Setting up our project

5.4.2 Writing the ML Wasm component

5.4.3 Updating our host to use ONNX for wasi:nn

5.5 Summary