Stop eagerly importing Store from haiku.rag.store
Import Store from haiku.rag.store.engine directly instead of re-exporting it through the package __init__, and defer HaikuRAGApp's import in cli.py behind TYPE_CHECKING/lazy imports, avoiding an eager import at CLI startup.
This commit is contained in:
parent
432c81149c
commit
5e6284fd02
9 changed files with 22 additions and 15 deletions
|
|
@ -4,7 +4,7 @@ import sys
|
|||
import warnings
|
||||
from importlib.metadata import version
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
import typer
|
||||
from dotenv import find_dotenv, load_dotenv
|
||||
|
|
@ -13,7 +13,6 @@ from dotenv import find_dotenv, load_dotenv
|
|||
# Env loading needs to be before config import; usecwd=True searches from cwd, not this .py file's location
|
||||
load_dotenv(find_dotenv(usecwd=True))
|
||||
|
||||
from haiku.rag.app import HaikuRAGApp # noqa: E402
|
||||
from haiku.rag.config import ( # noqa: E402
|
||||
AppConfig,
|
||||
find_config_file,
|
||||
|
|
@ -29,6 +28,9 @@ from haiku.rag.store.exceptions import ( # noqa: E402
|
|||
from haiku.rag.store.models.chunk import SearchType # noqa: E402
|
||||
from haiku.rag.utils import is_up_to_date # noqa: E402
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from haiku.rag.app import HaikuRAGApp
|
||||
|
||||
_cli = typer.Typer(
|
||||
context_settings={"help_option_names": ["-h", "--help"]},
|
||||
no_args_is_help=True,
|
||||
|
|
@ -48,7 +50,7 @@ def cli():
|
|||
_read_only: bool = False
|
||||
|
||||
|
||||
def create_app(db: Path | None = None) -> HaikuRAGApp: # pragma: no cover
|
||||
def create_app(db: Path | None = None) -> "HaikuRAGApp": # pragma: no cover
|
||||
"""Create HaikuRAGApp with loaded config and resolved database path.
|
||||
|
||||
Args:
|
||||
|
|
@ -57,6 +59,8 @@ def create_app(db: Path | None = None) -> HaikuRAGApp: # pragma: no cover
|
|||
Returns:
|
||||
HaikuRAGApp instance with proper config and db path.
|
||||
"""
|
||||
from haiku.rag.app import HaikuRAGApp
|
||||
|
||||
config = get_config()
|
||||
db_path = db if db else config.storage.data_dir / "haiku.rag.lancedb"
|
||||
return HaikuRAGApp(db_path=db_path, config=config, read_only=_read_only)
|
||||
|
|
@ -402,6 +406,8 @@ def analyze( # pragma: no cover
|
|||
|
||||
@_cli.command("settings", help="Display current configuration settings")
|
||||
def settings(): # pragma: no cover
|
||||
from haiku.rag.app import HaikuRAGApp
|
||||
|
||||
config = get_config()
|
||||
app = HaikuRAGApp(db_path=Path(), config=config, read_only=True)
|
||||
app.show_settings()
|
||||
|
|
@ -719,6 +725,8 @@ def tag_restore( # pragma: no cover
|
|||
|
||||
@_cli.command("download-models", help="Download Docling and Ollama models per config")
|
||||
def download_models_cmd(): # pragma: no cover
|
||||
from haiku.rag.app import HaikuRAGApp
|
||||
|
||||
app = HaikuRAGApp(db_path=Path(), config=get_config(), read_only=True)
|
||||
try:
|
||||
asyncio.run(app.download_models())
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
from .engine import Store
|
||||
from .exceptions import MigrationRequiredError, ReadOnlyError
|
||||
from .models import Chunk, Document
|
||||
|
||||
__all__ = ["Store", "Chunk", "Document", "MigrationRequiredError", "ReadOnlyError"]
|
||||
__all__ = ["Chunk", "Document", "MigrationRequiredError", "ReadOnlyError"]
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import pytest
|
||||
|
||||
from haiku.rag.store import Store
|
||||
from haiku.rag.store.engine import Store
|
||||
from haiku.rag.store.engine import get_database_stats
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ from importlib import metadata
|
|||
|
||||
import pytest
|
||||
|
||||
from haiku.rag.store import Store
|
||||
from haiku.rag.store.engine import Store
|
||||
from haiku.rag.store.exceptions import MigrationRequiredError
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,8 @@ from pathlib import Path
|
|||
import pytest
|
||||
|
||||
from haiku.rag.client import HaikuRAG
|
||||
from haiku.rag.store import ReadOnlyError, Store
|
||||
from haiku.rag.store import ReadOnlyError
|
||||
from haiku.rag.store.engine import Store
|
||||
from haiku.rag.store.models import Chunk, Document
|
||||
from haiku.rag.store.repositories.chunk import ChunkRepository
|
||||
from haiku.rag.store.repositories.document import DocumentRepository
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ import re
|
|||
import pytest
|
||||
from lancedb.table import AsyncTable, AsyncTags
|
||||
|
||||
from haiku.rag.store import ReadOnlyError, Store
|
||||
from haiku.rag.store.engine import RESTORE_TABLE_ORDER
|
||||
from haiku.rag.store import ReadOnlyError
|
||||
from haiku.rag.store.engine import RESTORE_TABLE_ORDER, Store
|
||||
from haiku.rag.store.models import Document
|
||||
from haiku.rag.store.repositories.document import DocumentRepository
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ import asyncio
|
|||
import pytest
|
||||
from lancedb.table import AsyncTags
|
||||
|
||||
from haiku.rag.store import ReadOnlyError, Store
|
||||
from haiku.rag.store.engine import REQUIRED_TABLES
|
||||
from haiku.rag.store import ReadOnlyError
|
||||
from haiku.rag.store.engine import REQUIRED_TABLES, Store
|
||||
from haiku.rag.store.models import Document
|
||||
from haiku.rag.store.repositories.document import DocumentRepository
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ introduced by later migrations (``picture_data`` in v0.45.0,
|
|||
|
||||
import pytest
|
||||
|
||||
from haiku.rag.store import Store
|
||||
from haiku.rag.store.engine import Store
|
||||
from haiku.rag.store.compression import compress_docling_split
|
||||
from haiku.rag.store.engine import DocumentRecord
|
||||
from haiku.rag.store.upgrades.v0_40_0 import _apply_populate_document_items
|
||||
|
|
|
|||
|
|
@ -12,9 +12,8 @@ import json
|
|||
import pyarrow as pa
|
||||
import pytest
|
||||
|
||||
from haiku.rag.store import Store
|
||||
from haiku.rag.store.compression import compress_json, decompress_json
|
||||
from haiku.rag.store.engine import DocumentItemRecord, DocumentRecord
|
||||
from haiku.rag.store.engine import DocumentItemRecord, DocumentRecord, Store
|
||||
from haiku.rag.store.upgrades.v0_45_0 import _apply_extract_picture_bytes
|
||||
|
||||
PNG_BYTES = b"\x89PNG\r\n\x1a\nfake-picture-bytes"
|
||||
|
|
|
|||
Loading…
Reference in a new issue