2025-03-18 23:27:53 -04:00
|
|
|
from typing import Dict, List, Optional, Any
|
2024-11-22 18:56:22 -05:00
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
2025-03-18 23:27:53 -04:00
|
|
|
from core.models.documents import Document
|
|
|
|
|
2024-11-22 18:56:22 -05:00
|
|
|
|
2024-12-26 08:52:25 -05:00
|
|
|
class RetrieveRequest(BaseModel):
|
|
|
|
"""Base retrieve request model"""
|
2024-12-26 11:34:24 -05:00
|
|
|
|
2024-11-28 19:09:40 -05:00
|
|
|
query: str = Field(..., min_length=1)
|
2024-11-22 18:56:22 -05:00
|
|
|
filters: Optional[Dict[str, Any]] = None
|
2024-11-28 19:09:40 -05:00
|
|
|
k: int = Field(default=4, gt=0)
|
|
|
|
min_score: float = Field(default=0.0)
|
2025-01-02 03:42:47 -05:00
|
|
|
use_reranking: Optional[bool] = None # If None, use default from config
|
2025-02-26 20:17:12 -05:00
|
|
|
use_colpali: Optional[bool] = None
|
2025-03-17 17:36:43 -04:00
|
|
|
graph_name: Optional[str] = Field(
|
|
|
|
None, description="Name of the graph to use for knowledge graph-enhanced retrieval"
|
|
|
|
)
|
|
|
|
hop_depth: Optional[int] = Field(
|
|
|
|
1, description="Number of relationship hops to traverse in the graph", ge=1, le=3
|
|
|
|
)
|
|
|
|
include_paths: Optional[bool] = Field(
|
|
|
|
False, description="Whether to include relationship paths in the response"
|
|
|
|
)
|
2024-12-26 08:52:25 -05:00
|
|
|
|
|
|
|
|
|
|
|
class CompletionQueryRequest(RetrieveRequest):
|
|
|
|
"""Request model for completion generation"""
|
2024-12-26 11:34:24 -05:00
|
|
|
|
2024-12-26 08:52:25 -05:00
|
|
|
max_tokens: Optional[int] = None
|
|
|
|
temperature: Optional[float] = None
|
2025-02-07 21:08:40 -05:00
|
|
|
|
|
|
|
|
|
|
|
class IngestTextRequest(BaseModel):
|
|
|
|
"""Request model for ingesting text content"""
|
|
|
|
|
|
|
|
content: str
|
2025-03-05 09:56:02 -06:00
|
|
|
filename: Optional[str] = None
|
2025-02-07 21:08:40 -05:00
|
|
|
metadata: Dict[str, Any] = Field(default_factory=dict)
|
|
|
|
rules: List[Dict[str, Any]] = Field(default_factory=list)
|
2025-02-26 20:17:12 -05:00
|
|
|
use_colpali: Optional[bool] = None
|
2025-03-17 17:36:43 -04:00
|
|
|
|
|
|
|
|
|
|
|
class CreateGraphRequest(BaseModel):
|
|
|
|
"""Request model for creating a graph"""
|
|
|
|
|
|
|
|
name: str = Field(..., description="Name of the graph to create")
|
|
|
|
filters: Optional[Dict[str, Any]] = Field(
|
|
|
|
None, description="Optional metadata filters to determine which documents to include"
|
|
|
|
)
|
|
|
|
documents: Optional[List[str]] = Field(
|
|
|
|
None, description="Optional list of specific document IDs to include"
|
|
|
|
)
|
2025-03-29 23:22:47 -07:00
|
|
|
|
|
|
|
|
|
|
|
class UpdateGraphRequest(BaseModel):
|
|
|
|
"""Request model for updating a graph"""
|
|
|
|
|
|
|
|
additional_filters: Optional[Dict[str, Any]] = Field(
|
|
|
|
None, description="Optional additional metadata filters to determine which new documents to include"
|
|
|
|
)
|
|
|
|
additional_documents: Optional[List[str]] = Field(
|
|
|
|
None, description="Optional list of additional document IDs to include"
|
|
|
|
)
|
2025-03-18 23:27:53 -04:00
|
|
|
|
|
|
|
|
|
|
|
class BatchIngestResponse(BaseModel):
|
|
|
|
"""Response model for batch ingestion"""
|
|
|
|
documents: List[Document]
|
|
|
|
errors: List[Dict[str, str]]
|
2025-03-27 17:30:02 -07:00
|
|
|
|
|
|
|
|
|
|
|
class GenerateUriRequest(BaseModel):
|
|
|
|
"""Request model for generating a cloud URI"""
|
|
|
|
app_id: str = Field(..., description="ID of the application")
|
|
|
|
name: str = Field(..., description="Name of the application")
|
|
|
|
user_id: str = Field(..., description="ID of the user who owns the app")
|
|
|
|
expiry_days: int = Field(default=30, description="Number of days until the token expires")
|