Merge pull request #485 from ggozad/fix/update-uri

Allow updating a document's uri via update_document
This commit is contained in:
Yiorgis Gozadinos 2026-07-08 10:41:24 +03:00 committed by GitHub
commit d71695833d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 22 additions and 0 deletions

View file

@ -1,6 +1,10 @@
# Changelog
## [Unreleased]
### Added
- `update_document` accepts a `uri` argument to change a document's URI.
## [0.63.2] - 2026-07-03
### Changed

View file

@ -141,6 +141,9 @@ await client.update_document(
# Update title only (no re-chunking)
await client.update_document(document_id=doc.id, title="New Title")
# Update uri only (no re-chunking)
await client.update_document(document_id=doc.id, uri="file:///new/path.txt")
# Update multiple fields at once
await client.update_document(
document_id=doc.id,

View file

@ -304,6 +304,7 @@ class HaikuRAG:
chunks: list[Chunk] | None = None,
title: str | None = None,
docling_document: "DoclingDocument | None" = None,
uri: str | None = None,
) -> Document:
from haiku.rag.client.documents import update_document
@ -315,6 +316,7 @@ class HaikuRAG:
chunks,
title,
docling_document,
uri,
)
async def get_document_by_id(self, document_id: str) -> Document | None:

View file

@ -810,6 +810,7 @@ async def update_document(
chunks: list[Chunk] | None = None,
title: str | None = None,
docling_document: "DoclingDocument | None" = None,
uri: str | None = None,
) -> Document:
"""Update a document by ID.
@ -837,6 +838,8 @@ async def update_document(
existing_doc.title = title
if metadata is not None:
existing_doc.metadata = metadata
if uri is not None:
existing_doc.uri = uri
if content is None and chunks is None and docling_document is None:
updated = await client.document_repository.update_meta(existing_doc)

View file

@ -256,6 +256,16 @@ async def test_client_update_document(qa_corpus: list[dict[str, str]], temp_db_p
assert doc_chunks[0].content == "Custom chunk 1"
assert doc_chunks[1].content == "Custom chunk 2"
# Test updating only the uri
new_uri = "file:///path/to/new.txt"
updated_doc = await client.update_document(document_id=original_id, uri=new_uri)
assert updated_doc.uri == new_uri
refetched = await client.get_document_by_id(original_id)
assert refetched is not None
assert refetched.uri == new_uri
assert (await client.get_document_by_uri(new_uri)) is not None
assert (await client.get_document_by_uri(test_uri)) is None
@pytest.mark.vcr()
async def test_client_create_document_from_source(temp_db_path):