- corpus/: Almeida (João Ferreira de Almeida) em USFX, domínio público, 66 livros / 1189 capítulos / 31098 versículos, versionado com SHA-256 - app/corpus.py: parser USFX (texto no tail de <v/>), nomes canônicos dos livros, aliases (abreviaturas e numerais romanos), VerseChunk sem página - indexer: descobre *.xml em CORPUS_DIR, progresso em versículos, lote configurável, manifesto incremental por SHA-256 - remove extraction.py, parallel.py, bible_parser.py, Tesseract e PyMuPDF - campo page removido de Source/SearchResult/StatusResponse e do frontend - embedder: propriedade name; status reporta o embedder em uso, não o do .env - create_app constrói o embedder ANTES do store (o default HashEmbedder do VectorStore impedia o modelo configurado de ser carregado em produção) - fallback do modelo agora aparece em /api/status.errors - torch 2.6.0 + transformers 5.22.1 pinados (transformers 5.x exige torch>=2.6)
74 lines
2.1 KiB
Python
74 lines
2.1 KiB
Python
"""Configuração do backend via variáveis de ambiente."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from functools import lru_cache
|
|
from pathlib import Path
|
|
|
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
"""Configuração lida do ambiente ou do arquivo .env."""
|
|
|
|
model_config = SettingsConfigDict(
|
|
env_file=(".env", "../.env"),
|
|
env_file_encoding="utf-8",
|
|
extra="ignore",
|
|
)
|
|
|
|
# Caminhos
|
|
corpus_dir: Path = Path("/data/corpus")
|
|
vector_db_dir: Path = Path("/data/vector_db")
|
|
|
|
# Provedor de LLM: ollama | openai | groq | anthropic | stub
|
|
llm_provider: str = "ollama"
|
|
ollama_base_url: str = "http://ollama:11434"
|
|
ollama_model: str = "qwen2.5:1.5b"
|
|
openai_base_url: str = "https://api.openai.com/v1"
|
|
openai_model: str = "gpt-4o-mini"
|
|
openai_api_key: str = ""
|
|
groq_base_url: str = "https://api.groq.com/openai/v1"
|
|
groq_model: str = "llama-3.3-70b-versatile"
|
|
groq_api_key: str = ""
|
|
anthropic_base_url: str = "https://api.anthropic.com"
|
|
anthropic_model: str = "claude-sonnet-4-5"
|
|
anthropic_api_key: str = ""
|
|
|
|
# Embeddings
|
|
embedding_model: str = "paraphrase-multilingual-MiniLM-L12-v2"
|
|
embedding_batch_size: int = 32
|
|
|
|
# Busca
|
|
top_k: int = 6
|
|
min_similarity: float = 0.35
|
|
collection_name: str = "biblia"
|
|
|
|
# Ingestão
|
|
# Tamanho do lote gravado no banco vetorial por vez: limita a memória e dá
|
|
# granularidade ao progresso da indexação.
|
|
index_batch_size: int = 512
|
|
|
|
# API
|
|
cors_origins: str = "http://localhost:8080,http://127.0.0.1:8080"
|
|
reindex_token: str = ""
|
|
max_message_length: int = 4000
|
|
max_history_turns: int = 10
|
|
|
|
# Indexação automática na inicialização
|
|
auto_index: bool = True
|
|
|
|
@property
|
|
def manifest_path(self) -> Path:
|
|
return self.vector_db_dir / "manifest.json"
|
|
|
|
@property
|
|
def cors_origin_list(self) -> list[str]:
|
|
return [origin.strip() for origin in self.cors_origins.split(",") if origin.strip()]
|
|
|
|
|
|
@lru_cache(maxsize=1)
|
|
def get_settings() -> Settings:
|
|
"""Devolve as settings singleton do processo."""
|
|
return Settings()
|