What
The build_index_sync function uses asyncio.run():
def build_index_sync(...) -> VectorStore:
return asyncio.run(build_index(source_dir, output_path))
asyncio.run() creates a new event loop. If called from within an already-running event loop (e.g., from a FastAPI startup event or an async script), it raises RuntimeError: This event loop is closed.
Why
This limits where the function can be called from.
Scope
- Document the limitation
- Or use
nest_asyncio / loop.run_until_complete for safer fallback
Acceptance Criteria
Technical Context
- File:
src/knowledge/index_builder.py, line 90
What
The
build_index_syncfunction usesasyncio.run():asyncio.run()creates a new event loop. If called from within an already-running event loop (e.g., from a FastAPI startup event or an async script), it raisesRuntimeError: This event loop is closed.Why
This limits where the function can be called from.
Scope
nest_asyncio/loop.run_until_completefor safer fallbackAcceptance Criteria
Technical Context
src/knowledge/index_builder.py, line 90