Overview
User scoping in Morphik allows multi-tenant applications to isolate data on a per-user basis. This ensures that in applications serving multiple users, each user can only access their own documents and data. User scoping is particularly valuable for building customer-facing applications where data privacy and separation are essential.Creating User Scopes
Operations Within a User Scope
Once you have a user scope, all operations performed on it are automatically scoped to that specific user. Documents created or retrieved are only accessible to that user.User Scope Methods
The UserScope class provides the same document operations as the main Morphik client, but automatically scoped to the specific user:ingest_text
- Ingest text content for this useringest_file
- Ingest a file for this useringest_files
- Ingest multiple files for this useringest_directory
- Ingest all files from a directory for this userretrieve_chunks
- Retrieve chunks matching a query from this user’s documentsretrieve_docs
- Retrieve documents matching a query from this user’s documentsquery
- Generate a completion using context from this user’s documents (supportsllm_config
parameter for custom LLM configuration)list_documents
- List all documents owned by this userbatch_get_documents
- Get multiple documents by their IDs for this userbatch_get_chunks
- Get specific chunks by source for this usercreate_graph
- Create a knowledge graph from this user’s documentsupdate_graph
- Update a knowledge graph with new documents from this userdelete_document_by_filename
- Delete a document by filename for this user