Skip to content

fix: Add support for 'basic' chunking strategy to match documentation #499

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions prepline_general/api/models/form_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,11 @@ def as_form(
] = False,
# -- chunking options --
chunking_strategy: Annotated[
Optional[Literal["by_title"]],
Optional[Literal["by_title", "basic"]],
Form(
title="Chunking Strategy",
description="Use one of the supported strategies to chunk the returned elements. Currently supports: by_title",
examples=["by_title"],
description="Use one of the supported strategies to chunk the returned elements. Currently supports: by_title and basic. Default: None",
examples=["by_title", "basic"],
),
] = None,
combine_under_n_chars: Annotated[
Expand Down
27 changes: 27 additions & 0 deletions test_general/api/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1153,3 +1153,30 @@ def test_include_slide_notes(monkeypatch, test_default, include_slide_notes, tes
assert "Here are important notes" == df["text"][0]
else:
assert "Here are important notes" != df["text"][0]

def test_basic_chunking_strategy():
"""
Verify that basic chunking strategy works as expected
"""
client = TestClient(app)
test_file = Path("sample-docs") / "layout-parser-paper-fast.pdf"
response = client.post(
MAIN_API_ROUTE,
files=[("files", (str(test_file), open(test_file, "rb")))],
data={"strategy": "hi_res"},
)
assert response.status_code == 200
response_without_chunking = response.json()

# chunking
response = client.post(
MAIN_API_ROUTE,
files=[("files", (str(test_file), open(test_file, "rb")))],
data={"chunking_strategy": "basic"},
)
assert response.status_code == 200

response_with_chunking = response.json()
assert len(response_with_chunking) != len(response_without_chunking)
assert "CompositeElement" in [element.get("type") for element in response_with_chunking]