Depends() lets you declare shared resources (DB session, vector store, API client) that FastAPI creates per request or reuses, which also makes testing easier by overriding them.
from fastapi import Depends
def get_store():
return vector_store
@app.get("/search")
async def search(q: str, store=Depends(get_store)):
return store.query(q)