Skip to content

Commit

Permalink
fix ci
Browse files Browse the repository at this point in the history
  • Loading branch information
Mini256 committed Feb 17, 2025
1 parent 7bcb7f8 commit 2b39d38
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
7 changes: 4 additions & 3 deletions backend/app/api/admin_routes/knowledge_base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
)
from app.exceptions import KBNoVectorIndexConfigured
from app.models import KgIndexStatus
from app.models.knowledge_base import IndexMethod, ChunkingConfig, GeneralChunkingConfig
from app.models.knowledge_base import IndexMethod, GeneralChunkingConfig, ChunkingConfig


class KnowledgeBaseCreate(BaseModel):
Expand Down Expand Up @@ -56,12 +56,13 @@ class KnowledgeBaseDetail(BaseModel):

id: int
name: str
description: str
description: Optional[str] = None
documents_total: int
data_sources_total: int
# Notice: By default, SQLModel will not serialize list type relationships.
# https://github.com/fastapi/sqlmodel/issues/37#issuecomment-2093607242
data_sources: list[KBDataSource]
chunking_config: Optional[ChunkingConfig] = None
index_methods: list[IndexMethod]
llm_id: int | None = None
llm: LLMDescriptor | None = None
Expand All @@ -79,7 +80,7 @@ class KnowledgeBaseItem(BaseModel):

id: int
name: str
description: str
description: Optional[str] = None
documents_total: int
data_sources_total: int
index_methods: list[IndexMethod]
Expand Down
2 changes: 1 addition & 1 deletion backend/app/api/admin_routes/knowledge_base/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def create_knowledge_base(
index_methods=create.index_methods,
llm_id=create.llm_id,
embedding_model_id=create.embedding_model_id,
chunking_config=create.chunking_config,
chunking_config=create.chunking_config.model_dump(),
data_sources=data_sources,
created_by=user.id,
updated_by=user.id,
Expand Down
10 changes: 6 additions & 4 deletions backend/app/models/knowledge_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,29 +96,31 @@ class ChunkingMode(str, enum.Enum):
ADVANCED = "advanced"


class ChunkingConfig(BaseModel):
class BaseChunkingConfig(BaseModel):
mode: ChunkingMode = Field(default=ChunkingMode.GENERAL)


class GeneralChunkingConfig(ChunkingConfig):
class GeneralChunkingConfig(BaseChunkingConfig):
mode: ChunkingMode = Field(default=ChunkingMode.GENERAL)
chunk_size: int = Field(default=DEFAULT_CHUNK_SIZE, gt=0)
chunk_overlap: int = Field(default=SENTENCE_CHUNK_OVERLAP, gt=0)
paragraph_separator: str = Field(default=DEFAULT_PARAGRAPH_SEP)


class AdvancedChunkingConfig(ChunkingConfig):
class AdvancedChunkingConfig(BaseChunkingConfig):
mode: ChunkingMode = Field(default=ChunkingMode.ADVANCED)
rules: Dict[MimeTypes, ChunkSplitterConfig] = Field(default_factory=list)


ChunkingConfig = Union[GeneralChunkingConfig | AdvancedChunkingConfig]

# Knowledge Base Model


class KnowledgeBase(SQLModel, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
name: str = Field(max_length=255, nullable=False)
description: str = Field(sa_column=Column(MEDIUMTEXT))
description: Optional[str] = Field(sa_column=Column(MEDIUMTEXT), default=None)

# The config for chunking, the process to break down the document into smaller chunks.
chunking_config: Dict = Field(
Expand Down
4 changes: 2 additions & 2 deletions frontend/app/src/api/knowledge-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export interface UpdateKnowledgeBaseParams {
export interface KnowledgeBaseSummary {
id: number;
name: string;
description: string;
description: string | null;
index_methods: KnowledgeBaseIndexMethod[];
documents_total?: number;
data_sources_total?: number;
Expand Down Expand Up @@ -94,7 +94,7 @@ export type KnowledgeGraphDocumentChunk = z.infer<typeof knowledgeGraphDocumentC
const knowledgeBaseSummarySchema = z.object({
id: z.number(),
name: z.string(),
description: z.string(),
description: z.string().nullable(),
index_methods: z.enum(['vector', 'knowledge_graph']).array(),
documents_total: z.number().optional(),
data_sources_total: z.number().optional(),
Expand Down

0 comments on commit 2b39d38

Please sign in to comment.