knowledge
Client for knowledge base endpoints including directories and file sync.
Classes
KnowledgeClient
KnowledgeClient(client: OWUIClientBase)
Bases: ResourceBase
Client for the Knowledge endpoints.
- Code Reference client Classes OpenWebUI Attributes knowledge
Source code in src/owui_client/client_base.py
Functions
get_knowledge
get_knowledge(page: int = 1) -> KnowledgeAccessListResponse
Get knowledge bases (read access).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
page
|
int
|
Page number (default 1). |
1
|
Returns:
| Type | Description |
|---|---|
KnowledgeAccessListResponse
|
|
Source code in src/owui_client/routers/knowledge.py
get_knowledge_list
get_knowledge_list() -> List[KnowledgeUserResponse]
Get knowledge bases list (write access).
Returns:
| Type | Description |
|---|---|
List[KnowledgeUserResponse]
|
List[KnowledgeUserResponse]: List of knowledge bases the user has write access to. |
Source code in src/owui_client/routers/knowledge.py
search_knowledge_bases
search_knowledge_bases(
query: Optional[str] = None,
view_option: Optional[str] = None,
page: Optional[int] = 1,
) -> KnowledgeAccessListResponse
Search knowledge bases.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
Optional[str]
|
Search query string. |
None
|
view_option
|
Optional[str]
|
View option filter (e.g., 'created', 'shared'). |
None
|
page
|
Optional[int]
|
Page number (default 1). |
1
|
Returns:
| Type | Description |
|---|---|
KnowledgeAccessListResponse
|
|
Source code in src/owui_client/routers/knowledge.py
search_knowledge_files
search_knowledge_files(
query: Optional[str] = None, page: Optional[int] = 1
) -> KnowledgeFileListResponse
Search files across all knowledge bases.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
Optional[str]
|
Search query string. |
None
|
page
|
Optional[int]
|
Page number (default 1). |
1
|
Returns:
| Type | Description |
|---|---|
KnowledgeFileListResponse
|
|
Source code in src/owui_client/routers/knowledge.py
create_new_knowledge
create_new_knowledge(
form_data: KnowledgeForm,
) -> Optional[KnowledgeResponse]
Create a new knowledge base.
Requires workspace.knowledge permission.
If access_control is None (public), requires sharing.public_knowledge permission.
If the user lacks sharing.public_knowledge permission, access_control will default to private {}.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
form_data
|
KnowledgeForm
|
The data for the new knowledge base. |
required |
Returns:
| Type | Description |
|---|---|
Optional[KnowledgeResponse]
|
Optional[KnowledgeResponse]: The created knowledge base. |
Source code in src/owui_client/routers/knowledge.py
get_knowledge_by_id
get_knowledge_by_id(
id: str,
) -> Optional[KnowledgeFilesResponse]
Get a knowledge base by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
str
|
The ID of the knowledge base. |
required |
Returns:
| Type | Description |
|---|---|
Optional[KnowledgeFilesResponse]
|
Optional[KnowledgeFilesResponse]: The knowledge base details including files. |
Source code in src/owui_client/routers/knowledge.py
update_knowledge_by_id
update_knowledge_by_id(
id: str, form_data: KnowledgeForm
) -> Optional[KnowledgeFilesResponse]
Update a knowledge base by ID.
Requires write access to the knowledge base or admin privileges.
If access_control is None (public), requires sharing.public_knowledge permission.
If the user lacks sharing.public_knowledge permission, access_control will default to private {}.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
str
|
The ID of the knowledge base. |
required |
form_data
|
KnowledgeForm
|
The updated data. |
required |
Returns:
| Type | Description |
|---|---|
Optional[KnowledgeFilesResponse]
|
Optional[KnowledgeFilesResponse]: The updated knowledge base. |
Source code in src/owui_client/routers/knowledge.py
update_knowledge_access
update_knowledge_access(
id: str, access_grants: list[dict]
) -> Optional[KnowledgeFilesResponse]
Update access grants for a knowledge base.
Requires write access to the knowledge base or admin privileges.
If setting public access (principal_id='*'), requires sharing.public_knowledge permission.
If the user lacks permission, public grants will be stripped.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
str
|
The ID of the knowledge base. |
required |
access_grants
|
list[dict]
|
List of access grant dictionaries. Each dict should contain:
- |
required |
Returns:
| Type | Description |
|---|---|
Optional[KnowledgeFilesResponse]
|
Optional[KnowledgeFilesResponse]: The updated knowledge base with files. |
Source code in src/owui_client/routers/knowledge.py
delete_knowledge_by_id
Delete a knowledge base by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
str
|
The ID of the knowledge base. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if successful. |
Source code in src/owui_client/routers/knowledge.py
add_file_to_knowledge
add_file_to_knowledge(
id: str,
file_id: str,
directory_id: Optional[str] = None,
) -> Optional[KnowledgeFilesResponse]
Add a file to a knowledge base.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
str
|
The ID of the knowledge base. |
required |
file_id
|
str
|
The ID of the file to add. |
required |
directory_id
|
Optional[str]
|
Optional directory ID to place the file in. None for root level. |
None
|
Returns:
| Type | Description |
|---|---|
Optional[KnowledgeFilesResponse]
|
Optional[KnowledgeFilesResponse]: The updated knowledge base. |
Source code in src/owui_client/routers/knowledge.py
update_file_from_knowledge
update_file_from_knowledge(
id: str, file_id: str
) -> Optional[KnowledgeFilesResponse]
Update a file in a knowledge base (re-process).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
str
|
The ID of the knowledge base. |
required |
file_id
|
str
|
The ID of the file to update. |
required |
Returns:
| Type | Description |
|---|---|
Optional[KnowledgeFilesResponse]
|
Optional[KnowledgeFilesResponse]: The updated knowledge base. |
Source code in src/owui_client/routers/knowledge.py
remove_file_from_knowledge
remove_file_from_knowledge(
id: str, file_id: str, delete_file: bool = True
) -> Optional[KnowledgeFilesResponse]
Remove a file from a knowledge base.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
str
|
The ID of the knowledge base. |
required |
file_id
|
str
|
The ID of the file to remove. |
required |
delete_file
|
bool
|
Whether to delete the file from the system as well. |
True
|
Returns:
| Type | Description |
|---|---|
Optional[KnowledgeFilesResponse]
|
Optional[KnowledgeFilesResponse]: The updated knowledge base. |
Source code in src/owui_client/routers/knowledge.py
reset_knowledge_by_id
reset_knowledge_by_id(
id: str,
) -> Optional[KnowledgeResponse]
Reset a knowledge base by ID (remove all files).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
str
|
The ID of the knowledge base. |
required |
Returns:
| Type | Description |
|---|---|
Optional[KnowledgeResponse]
|
Optional[KnowledgeResponse]: The reset knowledge base. |
Source code in src/owui_client/routers/knowledge.py
reindex_knowledge_files
Reindex all knowledge files.
This is a blocking operation that reprocesses all files in all knowledge bases. Requires Admin privileges.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if successful. |
Source code in src/owui_client/routers/knowledge.py
add_files_to_knowledge_batch
add_files_to_knowledge_batch(
id: str, file_ids: List[str]
) -> Optional[KnowledgeFilesResponse]
Add multiple files to a knowledge base in batch.
This process iterates through files and adds them to the vector database.
Failures are collected in the response warnings field.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
str
|
The ID of the knowledge base. |
required |
file_ids
|
List[str]
|
List of file IDs to add. |
required |
Returns:
| Type | Description |
|---|---|
Optional[KnowledgeFilesResponse]
|
Optional[KnowledgeFilesResponse]: The updated knowledge base. |
Optional[KnowledgeFilesResponse]
|
Check |
Source code in src/owui_client/routers/knowledge.py
create_knowledge_directory
create_knowledge_directory(
id: str, form_data: KnowledgeDirectoryCreateForm
) -> KnowledgeDirectoryModel
Create a new directory in a knowledge base.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
str
|
The ID of the knowledge base. |
required |
form_data
|
KnowledgeDirectoryCreateForm
|
The directory creation form with name and optional parent_id. |
required |
Returns:
| Type | Description |
|---|---|
KnowledgeDirectoryModel
|
|
Source code in src/owui_client/routers/knowledge.py
update_knowledge_directory
update_knowledge_directory(
id: str,
dir_id: str,
form_data: KnowledgeDirectoryUpdateForm,
) -> KnowledgeDirectoryModel
Update (rename or move) a directory in a knowledge base.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
str
|
The ID of the knowledge base. |
required |
dir_id
|
str
|
The ID of the directory to update. |
required |
form_data
|
KnowledgeDirectoryUpdateForm
|
The update form with optional name and parent_id. |
required |
Returns:
| Type | Description |
|---|---|
KnowledgeDirectoryModel
|
|
Source code in src/owui_client/routers/knowledge.py
delete_knowledge_directory
Delete a directory from a knowledge base.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
str
|
The ID of the knowledge base. |
required |
dir_id
|
str
|
The ID of the directory to delete. |
required |
move_files
|
bool
|
If True, contained files are moved to the parent directory. If False, files are also deleted. Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if successful. |
Source code in src/owui_client/routers/knowledge.py
move_file_in_knowledge
move_file_in_knowledge(
id: str, form_data: KnowledgeFileMoveForm
) -> bool
Move a file to a different directory within a knowledge base.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
str
|
The ID of the knowledge base. |
required |
form_data
|
KnowledgeFileMoveForm
|
The move form with file_id and optional directory_id. Set directory_id to None to move the file to the root. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if successful. |
Source code in src/owui_client/routers/knowledge.py
get_pending_knowledge_files
Get files that are still being processed for a knowledge base.
After a file is uploaded with a knowledge_id, the backend processes it in a background task before linking it to the knowledge_file join table. This endpoint exposes those in-flight files so they can be displayed with a processing indicator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
str
|
The ID of the knowledge base. |
required |
Returns:
| Type | Description |
|---|---|
list[dict]
|
list[dict]: List of pending file objects (each a file dict as |
list[dict]
|
returned by the backend). |
Source code in src/owui_client/routers/knowledge.py
sync_knowledge_diff
sync_knowledge_diff(
id: str, form_data: SyncDiffForm
) -> SyncDiffResponse
Compute a diff between a local file manifest and the knowledge base.
Returns which files need uploading, which are modified, which should be deleted, and which directories need to be created or removed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
str
|
The ID of the knowledge base. |
required |
form_data
|
SyncDiffForm
|
The sync diff form containing the local file manifest. |
required |
Returns:
| Type | Description |
|---|---|
SyncDiffResponse
|
|
Source code in src/owui_client/routers/knowledge.py
sync_knowledge_cleanup
sync_knowledge_cleanup(
id: str, form_data: SyncCleanupForm
) -> bool
Clean up stale files and orphaned directories after a sync.
Removes the specified file IDs and directory IDs from the knowledge base, including their embeddings from the vector database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
str
|
The ID of the knowledge base. |
required |
form_data
|
SyncCleanupForm
|
The cleanup form with file_ids and dir_ids to remove. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if successful. |
Source code in src/owui_client/routers/knowledge.py
reindex_metadata
Reindex knowledge base metadata embeddings.
Requires Admin privileges.
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
Statistics about the reindexing process (total, success). |
Source code in src/owui_client/routers/knowledge.py
export
Export a knowledge base as a zip file.
Requires Admin privileges.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
str
|
The ID of the knowledge base. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bytes |
bytes
|
The zip file content. |
Source code in src/owui_client/routers/knowledge.py
get_external_knowledge_connections
get_external_knowledge_connections() -> (
ExternalKnowledgeConnectionListResponse
)
List all external knowledge connections.
Returns connections with their secret auth_config stripped (replaced
by an auth_configured boolean). Admin only.
Returns:
| Type | Description |
|---|---|
ExternalKnowledgeConnectionListResponse
|
|
Source code in src/owui_client/routers/knowledge.py
create_external_knowledge_connection
create_external_knowledge_connection(
form_data: ExternalKnowledgeConnectionForm,
) -> dict
Create a new external knowledge connection.
Stores the connection under the external_knowledge.connections config
key. provider must be qdrant, milvus, or pgvector. Admin only.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
form_data
|
ExternalKnowledgeConnectionForm
|
Connection definition ( |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
The created connection, sanitized ( |
Raises:
| Type | Description |
|---|---|
HTTPException
|
400 if |
Source code in src/owui_client/routers/knowledge.py
get_external_knowledge_connection
Get a single external knowledge connection by id.
Admin only.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
str
|
The connection id. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
The sanitized connection (same shape as
|
Raises:
| Type | Description |
|---|---|
HTTPException
|
404 if the connection does not exist. |
Source code in src/owui_client/routers/knowledge.py
update_external_knowledge_connection
update_external_knowledge_connection(
id: str, form_data: ExternalKnowledgeConnectionForm
) -> dict
Update an existing external knowledge connection.
Fully replaces name/provider/endpoint/config/capabilities/enabled.
Pass auth_config=None to preserve the existing stored credentials, or
a dict to overwrite them. Admin only.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
str
|
The connection id. |
required |
form_data
|
ExternalKnowledgeConnectionForm
|
New connection definition. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
The updated sanitized connection. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
404 if the connection does not exist; 400 on invalid provider/fields. |
Source code in src/owui_client/routers/knowledge.py
delete_external_knowledge_connection
Delete an external knowledge connection.
Refuses deletion while any knowledge base still references it. Admin only.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
str
|
The connection id. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if deleted. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
404 if not found; 400 if still mapped to a knowledge base. |
Source code in src/owui_client/routers/knowledge.py
test_external_knowledge_connection
Record a health check for a connection.
Note: this does NOT actually connect to the external system. It records
ok = enabled and endpoint present, stamps checked_at, persists the
health dict on the connection, and returns it. Admin only.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
str
|
The connection id. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
Health record. Keys: |
Raises:
| Type | Description |
|---|---|
HTTPException
|
404 if the connection does not exist. |
Source code in src/owui_client/routers/knowledge.py
test_external_knowledge_source
test_external_knowledge_source(
form_data: ExternalKnowledgeSourceTestForm,
) -> dict
Run an ad-hoc retrieval test against a connection+source definition.
Does not persist anything. If connection_id is set, the stored
connection is loaded and merged with the supplied connection. The
backend embeds query, queries the external system, and normalizes the
results. Requires a working RAG embedding function. Admin only.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
form_data
|
ExternalKnowledgeSourceTestForm
|
|
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
Normalized retrieval result. Keys: |
Raises:
| Type | Description |
|---|---|
HTTPException
|
400 on bad source mapping or empty query; 404 if a
given |
Source code in src/owui_client/routers/knowledge.py
test_external_knowledge_retrieval
test_external_knowledge_retrieval(
id: str, form_data: ExternalKnowledgeRetrieveTestForm
) -> dict
Run an ad-hoc retrieval test against an existing connection by id.
Like test_external_knowledge_source but resolves the connection from
id instead of an inline definition. source is optional (defaults to
a test/payload.text source). Requires a working RAG embedding
function. Admin only.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
str
|
The connection id. |
required |
form_data
|
ExternalKnowledgeRetrieveTestForm
|
|
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
Normalized retrieval result ( |
Raises:
| Type | Description |
|---|---|
HTTPException
|
404 if the connection does not exist; 400 on empty query / bad source. |
Source code in src/owui_client/routers/knowledge.py
create_external_knowledge
create_external_knowledge(
form_data: ExternalKnowledgeCreateForm,
) -> Optional[KnowledgeResponse]
Create a read-only knowledge base backed by an EXISTING connection.
connection_id must already exist. Does not run a retrieval test. The
resulting knowledge base has meta.source == 'external' and
meta.read_only == True; local file operations are rejected. Note:
deleting this knowledge base also removes the referenced connection
(cascade). Admin only.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
form_data
|
ExternalKnowledgeCreateForm
|
|
required |
Returns:
| Type | Description |
|---|---|
Optional[KnowledgeResponse]
|
Optional[KnowledgeResponse]: The created (read-only, external-backed) knowledge base. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
404 if |
Source code in src/owui_client/routers/knowledge.py
create_external_knowledge_source
create_external_knowledge_source(
form_data: ExternalKnowledgeSourceCreateForm,
) -> Optional[KnowledgeResponse]
Create a connection AND a read-only external knowledge base in one step.
Before persisting, the backend runs a retrieval test using test_query
/ test_count; if it returns no documents the request fails with 400.
On success a new connection is stored and a read-only knowledge base is
created referencing it. Deleting the resulting knowledge base also
removes that connection (cascade). Requires a working RAG embedding
function. Admin only.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
form_data
|
ExternalKnowledgeSourceCreateForm
|
|
required |
Returns:
| Type | Description |
|---|---|
Optional[KnowledgeResponse]
|
Optional[KnowledgeResponse]: The created read-only external knowledge base. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
400 if name is empty, the test returns no results, or a KB already exists. |
Source code in src/owui_client/routers/knowledge.py
update_external_knowledge_source
update_external_knowledge_source(
id: str, form_data: ExternalKnowledgeSourceUpdateForm
) -> Optional[KnowledgeResponse]
Replace the connection+source backing an existing external knowledge base.
Resolves the knowledge base by id (must be external / read-only), then
re-runs a retrieval test (test_query / test_count); no documents =>
400. Updates the stored connection (same id, in place) and the knowledge
base meta. Requires a working RAG embedding function. Admin only.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
str
|
The external knowledge base id. |
required |
form_data
|
ExternalKnowledgeSourceUpdateForm
|
Full |
required |
Returns:
| Type | Description |
|---|---|
Optional[KnowledgeResponse]
|
Optional[KnowledgeResponse]: The updated external knowledge base. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
404 if the knowledge base or its connection is missing; 400 if the test returns no results. |