You've already forked DataMate
feat(knowledge-base): 添加知识库文件全库检索功能
- 新增相对路径字段替代原有的metadata存储方式 - 实现跨知识库文件检索接口searchFiles - 添加前端全库检索页面和相关API调用 - 优化文件路径处理和数据库索引配置 - 统一请求参数类型定义为RequestPayload和RequestParams - 简化RagFile模型中的元数据结构设计
This commit is contained in:
@@ -17,7 +17,7 @@ import {
|
||||
EditOutlined,
|
||||
ReloadOutlined,
|
||||
} from "@ant-design/icons";
|
||||
import { useNavigate, useParams } from "react-router";
|
||||
import { useNavigate, useParams, useSearchParams } from "react-router";
|
||||
import DetailHeader from "@/components/DetailHeader";
|
||||
import { SearchControls } from "@/components/SearchControls";
|
||||
import { KBFile, KnowledgeBaseItem } from "../knowledge-base.model";
|
||||
@@ -58,7 +58,6 @@ type KBFileRow = KBFile & {
|
||||
};
|
||||
|
||||
const PATH_SEPARATOR = "/";
|
||||
const RELATIVE_PATH_KEY = "relativePath";
|
||||
const normalizePath = (value?: string) =>
|
||||
(value ?? "").replace(/\\/g, PATH_SEPARATOR);
|
||||
|
||||
@@ -81,17 +80,13 @@ const splitRelativePath = (fullPath: string, prefix: string) => {
|
||||
};
|
||||
|
||||
const resolveFileRelativePath = (file: KBFile) => {
|
||||
const metadata = file?.metadata as Record<string, unknown> | undefined;
|
||||
const metadataPath =
|
||||
metadata && typeof metadata[RELATIVE_PATH_KEY] === "string"
|
||||
? String(metadata[RELATIVE_PATH_KEY])
|
||||
: "";
|
||||
const rawPath = metadataPath || file.fileName || file.name || "";
|
||||
const rawPath = file.relativePath || file.fileName || file.name || "";
|
||||
return normalizePath(rawPath).replace(/^\/+/, "");
|
||||
};
|
||||
|
||||
const KnowledgeBaseDetailPage: React.FC = () => {
|
||||
const navigate = useNavigate();
|
||||
const [searchParams] = useSearchParams();
|
||||
const { message } = App.useApp();
|
||||
const { id } = useParams<{ id: string }>();
|
||||
const [knowledgeBase, setKnowledgeBase] = useState<KnowledgeBaseItem | undefined>(undefined);
|
||||
@@ -158,6 +153,16 @@ const KnowledgeBaseDetailPage: React.FC = () => {
|
||||
}
|
||||
}, [id, fetchKnowledgeBaseDetails]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!id) {
|
||||
return;
|
||||
}
|
||||
const prefixParam = searchParams.get("prefix");
|
||||
const fileNameParam = searchParams.get("fileName");
|
||||
setFilePrefix(prefixParam ? normalizePrefix(prefixParam) : "");
|
||||
setFileKeyword(fileNameParam ? fileNameParam : "");
|
||||
}, [id, searchParams]);
|
||||
|
||||
useEffect(() => {
|
||||
if (id) {
|
||||
fetchFiles();
|
||||
|
||||
Reference in New Issue
Block a user