Post

Notion's AI can answer questions on any document you've created. But I have 1,000s of documents in my Notion—you can't put all these pages inside an AI prompt. How did they make it work? It's more interesting than you think ↓

First you need to understand embeddings. Embeddings turns words into lists of numbers, a vector, that represent how closely related they are, semantically. Spelling doesn't matter, for example "cat" and "dog" are closely linked, but "cat" and "car" are not.

1 repost3 likes

Every time a document is created, you can use a tool like @cohere.com to create embeddings, which helps your system understand the document's meaning and context, and not just its keywords. Whole chunks of text are given an embedding, so that their context can be fully understood.

Now querying is set up, we need to show AI how to use it. This is possible through "tool calling", which is a way to let AI call your functions. First, define which "tools" the AI can use, and how to use them. For example, this is a `search` tool for our vector database.

AI only writes text, but you can instruct the AI to use this tool by writing a JSON response when it wants to use it, like below. When you detect the AI has written this, you can parse the JSON, run the `search` function for real, and pass the results back to the AI.