Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions apps/api/app/api/v1/routes/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ async def list_document_chunks(
page: int = Query(1, ge=1, description="Page number"),
page_size: int = Query(50, ge=1, le=200, description="Items per page"),
chunk_type: DocumentChunkType | None = Query(None, description="Chunk type filter"),
include_asset_urls: bool = Query(False, description="Include generated asset URLs"),
current_user: CurrentUser = Depends(with_current_user),
db: AsyncSession = Depends(get_db),
):
Expand All @@ -93,7 +92,6 @@ async def list_document_chunks(
page=page,
page_size=page_size,
chunk_type=chunk_type,
include_asset_urls=include_asset_urls,
)
if response is None:
raise NotFoundException(
Expand All @@ -108,7 +106,6 @@ async def list_document_chunks(
async def get_document_chunk(
document_id: str,
document_chunk_id: str,
include_asset_urls: bool = Query(False, description="Include generated asset URLs"),
current_user: CurrentUser = Depends(with_current_user),
db: AsyncSession = Depends(get_db),
):
Expand All @@ -117,7 +114,6 @@ async def get_document_chunk(
user_id=current_user.user_id,
document_id=document_id,
document_chunk_id=document_chunk_id,
include_asset_urls=include_asset_urls,
)
if response is None:
raise NotFoundException(
Expand Down
42 changes: 0 additions & 42 deletions apps/api/app/services/document_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
invalidate_retrieval_cache_namespaces,
)
from shared.services.retrieval.graph_service import DocumentGraphService, GraphScope
from shared.services.storage.result_storage import get_result_storage

_MEDIA_CHUNK_TYPES = {"image", "table"}


def document_payload(document) -> dict[str, Any]:
Expand Down Expand Up @@ -74,7 +71,6 @@ async def list_document_chunks(
page: int,
page_size: int,
chunk_type: str | None,
include_asset_urls: bool,
) -> dict[str, Any] | None:
document = await self._repository.get_document(
db,
Expand Down Expand Up @@ -119,8 +115,6 @@ async def list_document_chunks(
self._chunk_payload(
chunk=chunk,
section=section,
job_id=job_result.job_id,
include_asset_urls=include_asset_urls,
)
for chunk, section, job_result in rows
]
Expand All @@ -147,7 +141,6 @@ async def get_document_chunk(
user_id: str,
document_id: str,
document_chunk_id: str,
include_asset_urls: bool,
) -> dict[str, Any] | None:
document = await self._repository.get_document(
db,
Expand Down Expand Up @@ -175,8 +168,6 @@ async def get_document_chunk(
"chunk": self._chunk_payload(
chunk=chunk,
section=section,
job_id=job_result.job_id,
include_asset_urls=include_asset_urls,
),
}

Expand All @@ -201,8 +192,6 @@ def _chunk_payload(
*,
chunk: DocumentChunk,
section: DocumentSection | None,
job_id: str,
include_asset_urls: bool,
) -> dict[str, Any]:
chunk_type = _normalize_chunk_type(chunk.chunk_type)
file_path = chunk.file_path
Expand All @@ -217,40 +206,9 @@ def _chunk_payload(
"file_path": file_path,
"sort_order": chunk.sort_order,
"metadata": chunk.chunk_metadata,
"asset_url": self._asset_url(
chunk_type=chunk_type,
file_path=file_path,
job_id=job_id,
include_asset_urls=include_asset_urls,
),
"created_at": _datetime_payload(chunk.created_at),
}

def _asset_url(
self,
*,
chunk_type: str,
file_path: str | None,
job_id: str,
include_asset_urls: bool,
) -> str | None:
if (
not include_asset_urls
or chunk_type not in _MEDIA_CHUNK_TYPES
or not file_path
):
return None

try:
result_storage = get_result_storage()
return result_storage.generate_artifact_url(
job_id=job_id,
artifact_ref=file_path,
)
except Exception as e:
logger.warning(f"Failed to generate document chunk asset URL: {e}")
return None

async def archive_document(
self,
db: AsyncSession,
Expand Down
2 changes: 0 additions & 2 deletions apps/api/tests/contract/test_documents_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,6 @@ async def test_should_list_current_document_chunks_by_document_id(
"file_path": None,
"sort_order": 0,
"metadata": {"summary": "Intro", "page_nums": [1]},
"asset_url": None,
"created_at": chunks[0]["created_at"],
}
]
Expand Down Expand Up @@ -747,7 +746,6 @@ async def test_should_return_one_document_chunk_by_document_chunk_id(
assert chunk["source_chunk_path"] == "Chapter 1/Figure"
assert chunk["file_path"] == "images/figure-1.png"
assert chunk["metadata"] == {"summary": "Figure", "page_nums": [3]}
assert chunk["asset_url"] is None
assert chunk["created_at"]


Expand Down
Loading