Integrate embedding generation into the resource creation workflow.
lib/actions/resources.ts
. This file has one function, createResource
, which, as the name implies, allows you to create a resource.
"use server";
directive at the top of the file. This means that it can be called anywhere in your Next.js application. This function will take an input, run it through a Zod schema to ensure it adheres to the correct schema, and then creates a new resource in the database. This is the ideal location to generate and store embeddings of the newly created resources.
generateEmbeddings
function created in the previous step, passing in the source material (content
). Once you have your embeddings of the source material, you can save them to the database, passing the resourceId
alongside each embedding.
lib/ai/embedding.ts
file:
Create the Test File
/tests/test-embeddings.js
:Add Test Script to package.json
package.json
:Update Dependencies
Run the Test
Check for Errors