fix: align with accepted structure (init_knowledge.py)
This commit is contained in:
+6
-2
@@ -4,7 +4,10 @@ from __future__ import annotations
|
|||||||
import argparse
|
import argparse
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from vector_store import add_document_to_store
|
try:
|
||||||
|
from knowledge_base import build_knowledge_base
|
||||||
|
except ModuleNotFoundError:
|
||||||
|
from .knowledge_base import build_knowledge_base
|
||||||
|
|
||||||
SUPPORTED_SUFFIXES = {".txt", ".md", ".markdown"}
|
SUPPORTED_SUFFIXES = {".txt", ".md", ".markdown"}
|
||||||
|
|
||||||
@@ -14,13 +17,14 @@ def load_directory(directory: str | Path) -> int:
|
|||||||
if not root.exists():
|
if not root.exists():
|
||||||
raise FileNotFoundError(f"Директория не найдена: {root}")
|
raise FileNotFoundError(f"Директория не найдена: {root}")
|
||||||
|
|
||||||
|
kb = build_knowledge_base()
|
||||||
total_chunks = 0
|
total_chunks = 0
|
||||||
for path in sorted(root.rglob("*")):
|
for path in sorted(root.rglob("*")):
|
||||||
if not path.is_file() or path.suffix.lower() not in SUPPORTED_SUFFIXES:
|
if not path.is_file() or path.suffix.lower() not in SUPPORTED_SUFFIXES:
|
||||||
continue
|
continue
|
||||||
content = path.read_text(encoding="utf-8")
|
content = path.read_text(encoding="utf-8")
|
||||||
title = str(path.relative_to(root))
|
title = str(path.relative_to(root))
|
||||||
total_chunks += add_document_to_store(content, title)
|
total_chunks += kb.add_document(content, title)
|
||||||
print(f"Загружен: {title} ({len(content)} символов)")
|
print(f"Загружен: {title} ({len(content)} символов)")
|
||||||
return total_chunks
|
return total_chunks
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user