The ai extension, taken live: a chat with tools and the shop's own notes, an answer read into a shape, and a vector store in the back end's database. The replies here are written beforehand in this page's file (fn aiReplay), so nothing is sent to any model; a program of your own leaves that fn out, and its provider answers.
An assistantAiChat is the kit's Chat, Message, MessageResponse and PromptInput over a server fn that runs the model and the program's tools until it is done, each turn streamed into the page as it is written. Ask how many lamps there are (a call of the stock tool: its result goes back, then the answer), or how long delivery takes (the nearest of the shop's notes, found in the vector store, is put before the model). Each turn is the signed-in person's, so a budget can say when they have had enough for the day.
Nobody is signed in.
Make a demo account (or sign in on the Back end page) and the chat opens here: the assistant talks to whoever is signed in.
A tool from a typed fnschema(pgAiStock) is the fn's parameters as a JSON Schema, written by the compiler: its names, their types, which may be left out, and the comment above the fn as its description. The model's input is checked against it before the fn runs; one that does not hold is sent back to the model as a failure. The same of a shape: schema(PgAiOrder).
json
An answer in a shapeaiObject holds the model to the schema (structured output at each provider) and reads what it wrote into the shape, checked: a typed value, or a failure that says which field is wrong.
A vector store in the databaseaiIndex embeds texts and keeps them in the AiVector model of this back end's own database; aiSearch embeds the question and compares it with every vector of the store (exact cosine, with bytes' dot), the nearest first. Here the vectors are local ones, the words themselves hashed, which find shared words; with AI_EMBED=openai, gemini, voyage or cohere they are a model's, which find meaning. Past some tens of thousands of vectors, Pinecone or Qdrant (the same file has both).