Sync your Notion knowledge base to OpenAI every night
Every night at 2am, we refresh your OpenAI knowledge base with the Notion pages your team edited that day, so your AI assistants and Slack bots stay accurate.
Build a code workflow that runs every night at 2am and keeps a company OpenAI vector store in sync with our Notion knowledge base, so downstream RAG workflows (a Slack bot, an in-app helper, an agent) always have fresh content.
This is a code workflow, not an agent. Every step is a known operation with structured inputs and outputs; there is no open-ended reasoning.
Trigger: cron, every day at 02:00 in the workspace's timezone (make the time configurable).
Configurable inputs I want to set at install time:
1) A list of Notion parent page IDs (or workspace scope) to watch. 2) The target OpenAI vector store name, defaulting to 'company-kb'. 3) The Slack channel to post the nightly summary in, e.g. #ops-kb-sync.
Steps:
1. Use Notion 'Search by Title' scoped to the configured parent pages, and filter results to pages whose last_edited_time is within the last 24 hours. Paginate until done.
2. For each matching page, call Notion 'Retrieve Page as Markdown' to grab the current content.
3. Maintain a persistent mapping of Notion pageId to OpenAI fileId in the workflow's state (keyed off the vector store name so multiple stores can coexist). Before uploading, if the page already has a saved fileId, call OpenAI 'Delete Vector Store File' to detach the previous version so we do not stack duplicates.
4. Write the markdown to a temporary file (name it after the page title so the file is human-readable in the OpenAI dashboard) and call OpenAI 'Upload File' with purpose 'assistants'.
5. Call OpenAI 'Create Vector Store File' to attach the new uploaded file to the configured vector store. If the vector store does not yet exist, create it once by name and cache its ID in state.
6. Update the pageId to fileId mapping in state so tomorrow's run can find the previous file if the page changes again.
7. After the batch is processed, call OpenAI 'List Vector Store Files' on the target vector store to get the current file count (across all pages in the store).
8. Post exactly one Slack Bot 'Send a Message' summary to the configured channel with: number of pages added or refreshed, number of pages that failed (with the page title and a short reason for each failure, up to say 10 listed), and the current total file count in the vector store. If zero pages changed, post a lightweight 'no changes tonight' note instead.
Robustness notes: if a single page errors out (unshared with the integration, markdown too large, upload failed, whatever), capture the error and keep going so one bad page never sinks the whole batch. Respect Notion and OpenAI rate limits by honoring their retry-after headers. The pageId to fileId mapping is the only piece of state you need to persist across runs; store it under a stable key so re-syncing the same page always replaces its previous upload rather than adding a new one.
Additional information
What does this prompt do?
- Finds every Notion page your team touched in the last 24 hours across the parent pages you want to sync.
- Uploads the fresh content to your OpenAI knowledge base so AI assistants stop giving stale answers.
- Replaces the previous copy of any updated page instead of piling on duplicates, using a saved mapping between Notion pages and OpenAI files.
- Posts a single Slack summary each morning with how many pages synced, how many failed, and how big the knowledge base is now.
What do I need to use this?
- A Notion workspace and an internal connection shared with the pages you want to sync.
- An OpenAI account with an existing knowledge base, or willingness to let us create one called 'company-kb'.
- A Slack workspace and the channel where the nightly summary should be posted.
How can I customize it?
- Change the sync time from 2am to any hour that fits your team's timezone.
- Point the workflow at any set of parent Notion pages, so you can sync a single wiki, a handbook, or your whole workspace.
- Rename the OpenAI knowledge base or change the Slack channel that receives the nightly summary.
Frequently asked questions
Will this create duplicate copies of my Notion pages in OpenAI?
Do I need Pinecone or another vector database?
What happens if one page fails to sync?
Can I use this to power a Slack RAG bot or a help center assistant?
Does this sync every page in Notion or only the ones that changed?
Related templates
Stop shipping AI assistants that answer with last month's docs.
Connect Notion, OpenAI, and Slack once, and Geni refreshes your knowledge base every night at 2am.