This ticket covers the implementation of the sync_database service. This is the primary write operation for the server, responsible for building the knowledge base from source files and embedding the content into the ChromaDB collection.
The implementation will adapt and combine the logic from two scripts:
buildScripts/ai/createKnowledgeBase.mjs (Parsing source files)
buildScripts/ai/embedKnowledgeBase.mjs (Scoring, embedding, and upserting to DB)
Since this is a long-running, asynchronous process, the service should be designed to run in the background without blocking the server.
Acceptance Criteria
- The
databaseService.mjs file is updated with a syncDatabase function.
- The function orchestrates the full build and embed process:
- It parses all knowledge sources (JSDoc, guides, etc.) into an in-memory array of chunks.
- It enriches the chunks (e.g., with inheritance chains).
- It performs a diff against the existing documents in ChromaDB to identify chunks to add, update, or delete.
- It generates embeddings for new/updated chunks and upserts them into the database.
- It deletes stale chunks from the database.
- The function is asynchronous and does not block the main thread.
- The
toolService.mjs serviceMapping is updated to point the sync_database operationId to the new service function.
This ticket covers the implementation of the
sync_databaseservice. This is the primary write operation for the server, responsible for building the knowledge base from source files and embedding the content into the ChromaDB collection.The implementation will adapt and combine the logic from two scripts:
buildScripts/ai/createKnowledgeBase.mjs(Parsing source files)buildScripts/ai/embedKnowledgeBase.mjs(Scoring, embedding, and upserting to DB)Since this is a long-running, asynchronous process, the service should be designed to run in the background without blocking the server.
Acceptance Criteria
databaseService.mjsfile is updated with asyncDatabasefunction.toolService.mjsserviceMappingis updated to point thesync_databaseoperationId to the new service function.