
type DocFilter = Record<string, any>;

type MessageItem = {
    role: 'system' | 'user' | 'assistant';
    content: string;
};

type PreProcessing = {
    need_instruction?: boolean;
    rewrite?: boolean;
    return_token_usage?: boolean;
    messages?: MessageItem[];
};

type PostProcessing = {
    rerank_switch?: boolean;
    rerank_model?: string;
    rerank_only_chunk?: boolean;
    retrieve_count?: number;
    chunk_diffusion_count?: number;
    chunk_group?: boolean;
    get_attachment_link?: boolean;
};

export type SearchKnowledgeRequest = {
    name?: string;
    project?: string;
    resource_id?: string;
    query: string;
    limit?: number;
    query_param?: {
        doc_filter?: DocFilter;
        dense_weight?: number;
    };
    pre_processing?: PreProcessing;
    post_processing?: PostProcessing;
};

type DocInfo = {
    doc_id: string;
    doc_name: string;
    create_time: number;
    doc_type: string;
    doc_meta: string;
    source: string;
    title: string;
};

type ChunkAttachment = {
    uuid: string;
    caption: string;
    type: string;
    link: string;
};

type ResultItem = {
    id: string;
    content: string;
    score: number;
    point_id: string;
    chunk_title: string;
    chunk_id: number;
    process_time: number;
    rerank_score?: number;
    doc_info: DocInfo;
    recall_position: number;
    rerank_position?: number;
    table_chunk_fields?: {
        field_name: string;
        field_value: string;
    }[];
    original_question?: string;
    chunk_type: string;
    chunk_attachment?: ChunkAttachment;
};

export type SearchKnowledgeResponse = {
    collection_name: string;
    count: number;
    rewrite_query?: string;
    token_usage?: {
        embedding_token_usage?: {
            prompt_tokens: number;
            completion_tokens: number;
            total_tokens: number;
        };
        rerank_token_usage?: number;
        rewrite_token_usage?: number;
    };
    result_list: ResultItem[];
};