RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.
Go agent-harnessagent-native-databaseagentic-aiagentic-retrievalagentic-searchaiai-agentscontext-enginecontext-engineeringcontext-managementharness-engineeringknowledge-compilationragretrieval-augmented-generationretrieval-harnesssearch-harness
import { MessageType, WebSearchProvider } from '@/constants/chat';
import { IAttachment } from '@/hooks/use-send-message';
export interface IDocumentDownloadInfo {
doc_id: string;
filename: string;
mime_type: string;
size?: number;
}
export interface AgenticRagOverride {
content?: string;
tools?: string[];
}
export interface AgenticRagTemplate {
id: string;
name: string;
description: string;
temperature?: number | null;
tools: string[];
content: string;
}
// Response of GET /api/v1/chats/:chat_id/agentic-rag
export interface IAgenticRagSettings {
base_template: string;
defaults: AgenticRagTemplate;
override: AgenticRagOverride | null;
effective: AgenticRagTemplate;
available_tools: Array<{ name: string; description: string }>;
using_defaults: boolean;
}
export interface PromptConfig {
empty_response: string;
parameters: Parameter[];
prologue: string;
system: string;
tts?: boolean;
quote: boolean;
keyword: boolean;
refine_multiturn: boolean;
use_kg: boolean;
reasoning?: boolean;
cross_languages?: Array<string>;
agentic_rag?: AgenticRagOverride | null;
anysearch_api_key?: string;
brave_api_key?: string;
exa_api_key?: string;
firecrawl_api_key?: string;
linkup_api_key?: string;
parallel_api_key?: string;
querit_api_key?: string;
search1api_api_key?: string;
searchapi_api_key?: string;
serply_api_key?: string;
tavily_api_key?: string;
youcom_api_key?: string;
web_search_provider?: WebSearchProvider;
}
export interface Parameter {
key: string;
optional: boolean;
}
export interface LlmSetting {
Creative: Variable;
Custom: Variable;
Evenly: Variable;
Precise: Variable;
}
export interface Variable {
frequency_penalty?: number;
max_tokens?: number;
presence_penalty?: number;
temperature?: number;
top_p?: number;
thinking?: 'default' | 'enabled' | 'disabled';
tenant_llm_id?: string;
model_type?: string;
}
export interface IDialog {
create_date: string;
create_time: number;
description: string;
icon: string;
id: string;
dialog_id?: string;
dataset_ids: string[];
kb_names: string[];
language: string;
llm_id: string;
tenant_llm_id?: string;
llm_setting: Variable;
llm_setting_type?: string;
name: string;
prompt_config: PromptConfig;
prompt_type: string;
status: string;
tenant_id: string;
update_date: string;
update_time: number;
keywords_similarity_weight?: number;
similarity_threshold: number;
top_k: number;
top_n: number;
meta_data_filter?: MetaDataFilter;
operator_permission: number;
nickname: string;
prefetch_size: number;
rerank_candidates_count: number;
rerank_id?: string;
tenant_rerank_id?: string;
}
export interface MetaDataFilter {
manual: Manual[];
method: string;
}
interface Manual {
key: string;
op: string;
value: string;
}
export interface IConversation {
create_date: string;
create_time: number;
chat_id: string;
id: string;
avatar: string;
messages: Message[];
name: string;
update_date: string;
update_time: number;
is_new: true;
}
export interface Message {
content: string;
role: MessageType;
doc_ids?: string[];
prompt?: string;
reference?: IReference;
id?: string;
audio_binary?: string;
data?: any;
files?: (File | UploadResponseDataType)[];
chatBoxId?: string;
attachment?: IAttachment;
downloads?: IDocumentDownloadInfo[];
usage?: ITurnUsage;
elapsed_ms?: number;
}
export interface IReferenceChunk {
citation_id?: string;
id: string;
chunk_id?: string;
content: null;
content_with_weight?: string;
document_id: string;
doc_id?: string;
document_name: string;
docnm_kwd?: string;
dataset_id: string;
kb_id?: string;
image_id: string;
img_id?: string;
similarity: number;
vector_similarity: number;
term_similarity: number;
positions: number[][];
doc_type?: string;
}
export interface IReference {
chunks: IReferenceChunk[];
doc_aggs: Docagg[];
total: number;
}
export interface IReferenceObject {
chunks: Record<string, IReferenceChunk>;
doc_aggs: Record<string, Docagg>;
}
/** One turn's token cost, reported by a final response or a history message. */
export interface ITurnUsage {
prompt_tokens: number;
completion_tokens: number;
total_tokens: number;
}
export interface IAnswer {
answer: string;
attachment?: IAttachment;
downloads?: IDocumentDownloadInfo[];
reference?: IReference;
conversationId?: string;
prompt?: string;
id?: string;
audio_binary?: string;
data?: any;
chatBoxId?: string;
/** Present when the final response reports token usage. */
usage?: ITurnUsage;
elapsed_ms?: number;
}
export interface Docagg {
count: number;
doc_id: string;
doc_name: string;
url?: string;
}
// interface Chunk {
// chunk_id: string;
// content_ltks: string;
// content_with_weight: string;
// doc_id: string;
// docnm_kwd: string;
// img_id: string;
// important_kwd: any[];
// kb_id: string;
// similarity: number;
// term_similarity: number;
// vector_similarity: number;
// }
export interface IToken {
create_date: string;
create_time: number;
tenant_id: string;
token: string;
update_date?: any;
update_time?: any;
beta: string;
}
export interface IStats {
pv: [string, number][];
uv: [string, number][];
speed: [string, number][];
tokens: [string, number][];
round: [string, number][];
thumb_up: [string, number][];
}
export interface IExternalChatInfo {
avatar?: string;
title: string;
prologue?: string;
has_tavily_key?: boolean;
has_web_search_provider?: boolean;
llm_id?: string;
}
export interface IMessage extends Message {
id: string;
awaitingServerId?: boolean;
conversationId?: string; // To distinguish which conversation the message belongs to
}
export interface IClientConversation extends IConversation {
messages: IMessage[];
}
export interface UploadResponseDataType {
created_at: number;
created_by: string;
extension: string;
id: string;
mime_type: string;
name: string;
preview_url: null;
size: number;
}