File size: 922 Bytes
ca133ee
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env python3
"""Document Memory Plugin"""
from typing import Dict, Any, Optional

class DocumentMemory:
    """Cache and manage uploaded documents."""
    def __init__(self):
        self.documents = {}
        self.metadata = {}
    
    def store_document(self, doc_id: str, content: Any, metadata: Dict[str, Any]):
        """Store document with metadata."""
        self.documents[doc_id] = content
        self.metadata[doc_id] = metadata
    
    def get_document(self, doc_id: str) -> Optional[Any]:
        """Retrieve document by ID."""
        return self.documents.get(doc_id)
    
    def list_documents(self) -> Dict[str, Dict[str, Any]]:
        """List all stored documents with metadata."""
        return {doc_id: self.metadata[doc_id] for doc_id in self.documents.keys()}
    
    def clear(self):
        """Clear all documents."""
        self.documents.clear()
        self.metadata.clear()