# COST: ZERO OpenAI tokens. # Reads ChromaDB metadata only — no embedding or similarity search performed. import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).parent.parent)) from dotenv import load_dotenv load_dotenv() from chroma import get_collection # noqa: E402 def list_indexed_documents() -> list[str]: """Return the names of all documents that have been indexed in the vector store. Queries the ChromaDB collection metadata to collect every unique 'source_file' value without loading any embeddings or performing any similarity search. No LLM call is made. This is useful for letting the agent know which documents are available before deciding whether to retrieve chunks or ask the user to upload more files. Returns: A sorted list of unique source file names (e.g. ['manual.pdf', 'notes.docx']). Returns an empty list if no documents have been indexed yet. """ collection = get_collection() if collection.count() == 0: return [] result = collection.get(include=["metadatas"]) seen: set[str] = set() for meta in result["metadatas"]: source = meta.get("source_file") if source: seen.add(source) return sorted(seen)