Create a database
Create a table
tenant_id
column? By specifying this column, You are making the table tenant aware. The rows in it will belong to specific tenants. If you leave it out, the table is considered shared, more on this later.
Get credentials
Get third party credentials
Set the environment
.env.example
to .env
Update NILE_USER and NILE_PASSWORD with the credentials you picked up in the previous step. It should look something like this:Run the application
Check the data in Nile
What's next?
/examples/quickstart/node_react/src/be/app.ts
.
app.post("/api/tenants/:tenantId/todos"
. This handler executes when users add new tasks.
This is what the handler code looks like:
findSimilarTasks
, aiEstimate
and embedTask
are all defined in AiUtils.ts
.
They are wrappers around standard AI model calls and database queries, and they handle the specifics of the AI model we are using.
This will make it easy to switch models in the future.
Getting similar tasks is done by querying the database for tasks with similar embeddings.
SEARCH_QUERY
task type. This is because we are looking for similar tasks to the new task. We use an embedding model
from the nomic
family, which is trained to perform specific types of embedding tasks. Telling it that we are generating the embedding for a lookup vs
generating an embedding that we will store with the document (as we’ll do in a bit), should help the model produce more relevant results.
As you can see, we filter out results where the cosine distance is higher than 1.
The lower the cosine distance is, the more similar the tasks are (0 indicate that they are identical).
A cosine distance of 1 means that the vectors are essentially unrelated, and when cosine distance is closer to 2, it indicates that the vectors are semantically opposites.
The embedTask
function uses the embedding model to generate the embedding and is a very simple wrapper on the model:
aiEstimate
to generate the time estimate.
This function also wraps a model, this time a conversation model rather than an embedding model. And it icludes the similar tasks in the promopt, so the model will
generate similar estimates:
.env
file to connect with the API: