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
3 changes: 3 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ jobs:
python-version: ${{ matrix.python-version }}
cache: pip
- run: pip install -r requirements.txt pytest
- if: matrix.agent-frameworks == 'without'
# requirements.txt carries it; this leg tests the no-framework paths
run: pip uninstall -y openai-agents
- if: matrix.agent-frameworks == 'with'
run: pip install openai-agents claude-agent-sdk anthropic
- run: python -m pytest -q
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ __pycache__
logs/
.pageindex/
dist/
*.doc_id
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ python3 run_pageindex.py --pdf_path /path/to/your/document.pdf
<details>
<summary>Optional parameters</summary>
<br>
You can customize the processing with additional optional arguments (the structure-tuning flags below require <code>--mode standard</code>):
You can customize the processing with additional optional arguments (the structure-tuning flags from <code>--toc-check-pages</code> down require <code>--mode standard</code>):

```
--mode Processing mode: flash (default) or standard
Expand Down
23 changes: 4 additions & 19 deletions examples/agentic_vectorless_rag_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,13 @@
from agents.stream_events import RawResponsesStreamEvent, RunItemStreamEvent
from openai.types.responses import ResponseTextDeltaEvent, ResponseReasoningSummaryTextDeltaEvent

from pageindex import PageIndexAPIError, PageIndexLocalClient
from pageindex import PageIndexLocalClient
import pageindex.utils as utils

PDF_URL = "https://arxiv.org/pdf/2603.15031"

_EXAMPLES_DIR = Path(__file__).parent
PDF_PATH = _EXAMPLES_DIR / "documents" / "attention-residuals.pdf"
DOC_ID_PATH = _EXAMPLES_DIR / "documents" / "attention-residuals.doc_id"
STORAGE_PATH = _EXAMPLES_DIR / ".pageindex"


Expand Down Expand Up @@ -127,27 +126,13 @@ async def _run():
print("=" * 60)
print("Step 1: Index PDF and view tree structure")
print("=" * 60)
doc_id = None
if DOC_ID_PATH.exists():
cached = DOC_ID_PATH.read_text().strip()
try:
client.get_document(cached)
doc_id = cached
except PageIndexAPIError:
DOC_ID_PATH.unlink()
if doc_id is None:
# The .doc_id cache is gitignored — on a fresh clone with an
# existing store, find the already-indexed copy by name instead of
# re-indexing it.
doc_id = next(
(doc["id"] for doc in client.list_documents(limit=100)["documents"]
if doc["name"] == PDF_PATH.name), None)
doc_id = next(
(doc["id"] for doc in client.list_documents(limit=100)["documents"]
if doc["name"] == PDF_PATH.name), None)
if doc_id:
DOC_ID_PATH.write_text(doc_id)
print(f"\nLoaded cached doc_id: {doc_id}")
else:
doc_id = client.submit_document(str(PDF_PATH), wait=True)["doc_id"]
DOC_ID_PATH.write_text(doc_id)
print(f"\nIndexed. doc_id: {doc_id}")
print("\nTree Structure (top-level sections):")
structure = client.get_tree(doc_id, node_summary=True)["result"]
Expand Down
20 changes: 3 additions & 17 deletions pageindex/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
"""PageIndex SDK."""
import os as _os
from typing import TYPE_CHECKING as _TYPE_CHECKING

# LiteLLM's import otherwise fetches its model map over the network — seconds
# of blocking (or a hang offline). setdefault, so an explicit user choice wins.
_os.environ.setdefault("LITELLM_LOCAL_MODEL_COST_MAP", "True")

from .client import PageIndexClient, PageIndexCloudClient, PageIndexLocalClient
from .errors import PageIndexAPIError

Expand All @@ -23,8 +18,6 @@
]

_LAZY = {
"page_index": ".page_index_classic",
"page_index_main": ".page_index_classic",
"page_index_flash": ".flash",
"optimize_tree": ".tree_optimize",
"md_to_tree": ".page_index_md",
Expand All @@ -34,25 +27,18 @@
"mcp_bridge", "page_index_classic", "page_index_md",
"tree_optimize", "utils"}


def __getattr__(name):
if name.startswith("_"):
# Dunder probes (copy, pickle, inspect) are the frequent unknown
# names — they must not trigger the classic import below.
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
import importlib
if name in _SUBMODULES:
return importlib.import_module(f".{name}", __name__)
# Pre-0.2.10 compat: unknown names fall through to the classic module,
# whose public surface (ConfigLoader, count_tokens, ...) resolved as
# package attributes. A non-underscore typo pays one classic import
# before its AttributeError — not worth an allowlist.
module = importlib.import_module(_LAZY.get(name, ".page_index_classic"),
__name__)
module = importlib.import_module(_LAZY.get(name, ".page_index_classic"), __name__)
try:
value = getattr(module, name)
except AttributeError:
raise AttributeError(
f"module {__name__!r} has no attribute {name!r}") from None
raise AttributeError(f"module {__name__!r} has no attribute {name!r}") from None
globals()[name] = value
return value

Expand Down
Loading
Loading