mirror of
https://github.com/VectifyAI/PageIndex.git
synced 2026-07-15 21:11:05 +02:00
Engineering-quality cleanups from the SDK review (no behavior change):
- Return-type discoverability: add pageindex/types.py with TypedDicts
(DocumentInfo, DocumentDetail, PageContent) and annotate Collection /
Backend methods with them; add docstrings to every public Collection
method (including the get_page_content `pages` spec). Exported from the
package. Zero runtime cost — these are plain dicts.
- Backend protocol as a real contract:
* query_stream is an async generator, so the protocol now declares it
as `def ... -> AsyncIterator[QueryEvent]` (not `async def`, which
typed it as a coroutine and never matched the implementations).
* custom-parser support is expressed as a runtime_checkable
SupportsParserRegistration capability protocol; the client uses
isinstance(...) instead of hasattr(...) duck-typing.
- Parser layering: move count_tokens into a leaf module pageindex/tokens.py
so parser/* imports it from there instead of reaching back into
pageindex.index (a reverse dependency). index.utils re-exports it for
backward compatibility.
Adds tests/test_architecture.py enforcing: parser never imports index,
count_tokens is a single shared leaf, the capability protocol works,
both backends satisfy Backend, and the TypedDicts are exported.
Claude-Session: https://claude.ai/code/session_01Kx5DgKbhK1N8autqXH8SmS
49 lines
1.4 KiB
Python
49 lines
1.4 KiB
Python
# pageindex/__init__.py
|
|
# Upstream exports (backward compatibility). Import from the canonical
|
|
# pageindex.index.* modules directly so `import pageindex` does NOT trip the
|
|
# top-level deprecation shims (pageindex.page_index / .page_index_md / .utils).
|
|
from .index.page_index import *
|
|
from .index.page_index_md import md_to_tree
|
|
from .retrieve import get_document, get_document_structure, get_page_content
|
|
|
|
# SDK exports
|
|
from .client import PageIndexClient, LocalClient, CloudClient
|
|
from .config import IndexConfig, set_llm_params
|
|
from .collection import Collection
|
|
from .types import DocumentInfo, DocumentDetail, PageContent
|
|
from .parser.protocol import ContentNode, ParsedDocument, DocumentParser
|
|
from .storage.protocol import StorageEngine
|
|
from .events import QueryEvent
|
|
from .errors import (
|
|
PageIndexError,
|
|
PageIndexAPIError,
|
|
CollectionNotFoundError,
|
|
DocumentNotFoundError,
|
|
IndexingError,
|
|
CloudAPIError,
|
|
FileTypeError,
|
|
)
|
|
|
|
__all__ = [
|
|
"PageIndexClient",
|
|
"LocalClient",
|
|
"CloudClient",
|
|
"IndexConfig",
|
|
"set_llm_params",
|
|
"Collection",
|
|
"DocumentInfo",
|
|
"DocumentDetail",
|
|
"PageContent",
|
|
"ContentNode",
|
|
"ParsedDocument",
|
|
"DocumentParser",
|
|
"StorageEngine",
|
|
"QueryEvent",
|
|
"PageIndexError",
|
|
"PageIndexAPIError",
|
|
"CollectionNotFoundError",
|
|
"DocumentNotFoundError",
|
|
"IndexingError",
|
|
"CloudAPIError",
|
|
"FileTypeError",
|
|
]
|