list_documents
Retrieve a paginated list of all documents stored in the Chroma vector database, specifying limit and offset for efficient navigation and management.
Instructions
List all documents stored in the Chroma vector database with pagination
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | ||
| offset | No |
Implementation Reference
- src/chroma/server.py:575-614 (handler)The core handler function for executing the 'list_documents' tool. It extracts limit and offset from arguments, queries the Chroma collection using collection.get(), formats the results (IDs, content, metadata) into a structured text response, and handles errors with DocumentOperationError. Includes retry decorator for reliability.@retry_operation("list_documents") async def handle_list_documents(arguments: dict) -> list[types.TextContent]: """Handle document listing with retry logic""" limit = arguments.get("limit", 10) offset = arguments.get("offset", 0) try: # Get all documents results = collection.get( limit=limit, offset=offset, include=['documents', 'metadatas'] ) if not results or not results.get('ids'): return [ types.TextContent( type="text", text="No documents found in collection" ) ] # Format results response = [f"Documents (showing {len(results['ids'])} results):"] for i, (doc_id, content, metadata) in enumerate( zip(results['ids'], results['documents'], results['metadatas']) ): response.append(f"\nID: {doc_id}") response.append(f"Content: {content}") if metadata: response.append(f"Metadata: {metadata}") return [ types.TextContent( type="text", text="\n".join(response) ) ] except Exception as e: raise DocumentOperationError(str(e))
- src/chroma/server.py:295-305 (registration)Registration of the 'list_documents' tool in the @server.list_tools() handler. Defines the tool's name, description, and input schema supporting optional pagination parameters (limit, offset).types.Tool( name="list_documents", description="List all documents stored in the Chroma vector database with pagination", inputSchema={ "type": "object", "properties": { "limit": {"type": "integer", "minimum": 1, "default": 10}, "offset": {"type": "integer", "minimum": 0, "default": 0} } } ),
- src/chroma/server.py:339-340 (registration)Dispatch logic in the main @server.call_tool() handler that routes 'list_documents' calls to the specific handle_list_documents function.elif name == "list_documents": return await handle_list_documents(arguments)
- src/chroma/server.py:172-178 (schema)Input schema for the 'list_documents' tool defined in server.command_options, specifying pagination parameters with types, constraints, and defaults."list_documents": { "type": "object", "properties": { "limit": {"type": "integer", "minimum": 1, "default": 10}, "offset": {"type": "integer", "minimum": 0, "default": 0} } },