diff --git a/.gitignore b/.gitignore index b3e052c..4cc5b7b 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,8 @@ backend/.pytest_cache/ backend/*.egg-info/ backend/**/__pycache__/ backend/.env +# 运行期生成的 SQLite 索引(vault 下的 Markdown 测试数据需提交) +backend/data/*.db* # Editors and operating systems .idea/ diff --git a/backend/app/config.py b/backend/app/config.py index dcc4054..20b0cef 100644 --- a/backend/app/config.py +++ b/backend/app/config.py @@ -1,25 +1,40 @@ import os from dataclasses import dataclass from functools import lru_cache +from pathlib import Path + +# backend 目录(本文件位于 backend/app/config.py,父目录的父目录即 backend) +BACKEND_DIR = Path(__file__).resolve().parent.parent @dataclass(frozen=True) class Settings: - """应用基础配置;正式环境可通过 APP_* 环境变量覆盖。""" + """应用基础配置;正式环境可通过 APP_* 环境变量覆盖。 + + 数据目录默认落在 backend/data 下:app.db 保存 SQLite 索引, + vault/ 保存 Markdown 笔记。三者均可通过环境变量覆盖,便于测试与正式部署分离。 + """ name: str version: str environment: str host: str port: int + data_dir: Path + db_path: Path + vault_path: Path @lru_cache def get_settings() -> Settings: + data_dir = Path(os.getenv("APP_DATA_DIR", str(BACKEND_DIR / "data"))) return Settings( name=os.getenv("APP_NAME", "Notes Agent AI Core"), version=os.getenv("APP_VERSION", "0.1.0"), environment=os.getenv("APP_ENVIRONMENT", "development"), host=os.getenv("APP_HOST", "127.0.0.1"), port=int(os.getenv("APP_PORT", "8000")), + data_dir=data_dir, + db_path=Path(os.getenv("APP_DB_PATH", str(data_dir / "app.db"))), + vault_path=Path(os.getenv("APP_VAULT_PATH", str(data_dir / "vault"))), ) diff --git a/backend/pyproject.toml b/backend/pyproject.toml index 64ca599..81978c8 100644 --- a/backend/pyproject.toml +++ b/backend/pyproject.toml @@ -7,6 +7,7 @@ requires-python = ">=3.11" dependencies = [ "fastapi>=0.116,<1.0", "httpx>=0.28,<1.0", + "sqlite-vec>=0.1.9", "uvicorn[standard]>=0.35,<1.0", ] diff --git a/backend/uv.lock b/backend/uv.lock index ecebb4b..4c5f0d4 100644 --- a/backend/uv.lock +++ b/backend/uv.lock @@ -181,6 +181,7 @@ source = { virtual = "." } dependencies = [ { name = "fastapi" }, { name = "httpx" }, + { name = "sqlite-vec" }, { name = "uvicorn", extra = ["standard"] }, ] @@ -193,6 +194,7 @@ dev = [ requires-dist = [ { name = "fastapi", specifier = ">=0.116,<1.0" }, { name = "httpx", specifier = ">=0.28,<1.0" }, + { name = "sqlite-vec", specifier = ">=0.1.9" }, { name = "uvicorn", extras = ["standard"], specifier = ">=0.35,<1.0" }, ] @@ -423,6 +425,18 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/f1/12/de94a39c2ef588c7e6455cfbe7343d3b2dc9d6b6b2f40c4c6565744c873d/pyyaml-6.0.3-cp314-cp314t-win_arm64.whl", hash = "sha256:ebc55a14a21cb14062aa4162f906cd962b28e2e9ea38f9b4391244cd8de4ae0b", size = 149341, upload-time = "2025-09-25T21:32:56.828Z" }, ] +[[package]] +name = "sqlite-vec" +version = "0.1.9" +source = { registry = "https://pypi.org/simple" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/68/85/9fad0045d8e7c8df3e0fa5a56c630e8e15ad6e5ca2e6106fceb666aa6638/sqlite_vec-0.1.9-py3-none-macosx_10_6_x86_64.whl", hash = "sha256:1b62a7f0a060d9475575d4e599bbf94a13d85af896bc1ce86ee80d1b5b48e5fb", size = 131171, upload-time = "2026-03-31T08:02:31.717Z" }, + { url = "https://files.pythonhosted.org/packages/a4/3d/3677e0cd2f92e5ebc43cd29fbf565b75582bff1ccfa0b8327c7508e1084f/sqlite_vec-0.1.9-py3-none-macosx_11_0_arm64.whl", hash = "sha256:1d52e30513bae4cc9778ddbf6145610434081be4c3afe57cd877893bad9f6b6c", size = 165434, upload-time = "2026-03-31T08:02:32.712Z" }, + { url = "https://files.pythonhosted.org/packages/00/d4/f2b936d3bdc38eadcbd2a87875815db36430fab0363182ba5d12cd8e0b51/sqlite_vec-0.1.9-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:4e921e592f24a5f9a18f590b6ddd530eb637e2d474e3b1972f9bbeb773aa3cb9", size = 160076, upload-time = "2026-03-31T08:02:33.796Z" }, + { url = "https://files.pythonhosted.org/packages/6f/ad/6afd073b0f817b3e03f9e37ad626ae341805891f23c74b5292818f49ac63/sqlite_vec-0.1.9-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux1_x86_64.whl", hash = "sha256:1515727990b49e79bcaf75fdee2ffc7d461f8b66905013231251f1c8938e7786", size = 163388, upload-time = "2026-03-31T08:02:34.888Z" }, + { url = "https://files.pythonhosted.org/packages/42/89/81b2907cda14e566b9bf215e2ad82fc9b349edf07d2010756ffdb902f328/sqlite_vec-0.1.9-py3-none-win_amd64.whl", hash = "sha256:4a28dc12fa4b53d7b1dced22da2488fade444e96b5d16fd2d698cd670675cf32", size = 292804, upload-time = "2026-03-31T08:02:36.035Z" }, +] + [[package]] name = "starlette" version = "1.6.0"