/documents and /knowledge working (again)

This commit is contained in:
phernandez
2024-12-23 20:48:22 -06:00
parent 3b8038665c
commit 1c56b23f75
8 changed files with 218 additions and 357 deletions
+32 -2
View File
@@ -1,9 +1,39 @@
"""Main CLI entry point for basic-memory"""
import asyncio
from pathlib import Path
import typer
from basic_memory.db import engine_session_factory, DatabaseType
app = typer.Typer()
# app.add_typer(migrate.app, name="migrate")
@app.command()
def init_db(
project_path: str = typer.Argument(..., help="Path to project directory"),
force: bool = typer.Option(False, "--force", "-f", help="Force reinitialization if database exists")
):
"""Initialize a new project database."""
async def _init_db():
path = Path(project_path)
db_path = path / "data" / "memory.db"
if db_path.exists() and not force:
typer.echo(f"Database already exists at {db_path}. Use --force to reinitialize.")
raise typer.Exit(1)
# Create data directory if needed
db_path.parent.mkdir(parents=True, exist_ok=True)
try:
async with engine_session_factory(path, db_type=DatabaseType.FILESYSTEM, init=True):
typer.echo(f"Initialized database at {db_path}")
except Exception as e:
typer.echo(f"Error initializing database: {e}")
raise typer.Exit(1)
asyncio.run(_init_db())
if __name__ == "__main__": # pragma: no cover
app()
app()