read_document
Retrieve a specific document from the Chroma vector database using its unique ID, enabling efficient document access and management for semantic search and metadata filtering.
Instructions
Retrieve a document from the Chroma vector database by its ID
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| document_id | Yes |
Implementation Reference
- src/chroma/server.py:411-448 (handler)Main execution logic for the read_document tool: extracts document_id, fetches from Chroma collection using collection.get(), handles not found errors, formats content and metadata into TextContent response.@retry_operation("read_document") async def handle_read_document(arguments: dict) -> list[types.TextContent]: """Handle document reading with retry logic""" doc_id = arguments.get("document_id") if not doc_id: raise DocumentOperationError("Missing document_id") logger.info(f"Reading document with ID: {doc_id}") try: result = collection.get(ids=[doc_id]) if not result or not result.get('ids') or len(result['ids']) == 0: raise DocumentOperationError(f"Document not found [id={doc_id}]") logger.info(f"Successfully retrieved document: {doc_id}") # Format the response doc_content = result['documents'][0] doc_metadata = result['metadatas'][0] if result.get('metadatas') else {} response = [ f"Document ID: {doc_id}", f"Content: {doc_content}", f"Metadata: {doc_metadata}" ] return [ types.TextContent( type="text", text="\n".join(response) ) ] except Exception as e: raise DocumentOperationError(str(e))
- src/chroma/server.py:257-267 (schema)Input schema definition for read_document tool, exposed via the list_tools() handler. Requires 'document_id' string.types.Tool( name="read_document", description="Retrieve a document from the Chroma vector database by its ID", inputSchema={ "type": "object", "properties": { "document_id": {"type": "string"} }, "required": ["document_id"] } ),
- src/chroma/server.py:333-334 (registration)Dispatch logic in the @server.call_tool() handler that routes 'read_document' calls to the handle_read_document function.elif name == "read_document": return await handle_read_document(arguments)
- src/chroma/server.py:149-155 (schema)Internal command_options schema for read_document tool validation, identical to the exposed schema."read_document": { "type": "object", "properties": { "document_id": {"type": "string"} }, "required": ["document_id"] },