mirror of
https://git.mirrors.martin98.com/https://github.com/infiniflow/ragflow.git
synced 2025-06-04 11:24:00 +08:00
Feat: Support knowledge base type input in agent flow debugger (#7471)
### What problem does this PR solve? This is a follow-up of #7088 , adding a knowledge base type input to the `Begin` component, and a knowledge base selector to the agent flow debug input panel:  then you can select one or more knowledge bases when testing the agent:  Note: the lines changed in `agent/component/retrieval.py` after line 94 are modified by `ruff format` from the `pre-commit` hooks, no functional change. ### Type of change - [ ] Bug Fix (non-breaking change which fixes an issue) - [x] New Feature (non-breaking change which adds functionality) - [ ] Documentation Update - [ ] Refactoring - [ ] Performance Improvement - [ ] Other (please describe):
This commit is contained in:
parent
75b24ba02a
commit
bc3160f75a
@ -30,10 +30,10 @@ from rag.utils.tavily_conn import Tavily
|
|||||||
|
|
||||||
|
|
||||||
class RetrievalParam(ComponentParamBase):
|
class RetrievalParam(ComponentParamBase):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Define the Retrieval component parameters.
|
Define the Retrieval component parameters.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.similarity_threshold = 0.2
|
self.similarity_threshold = 0.2
|
||||||
@ -67,7 +67,10 @@ class Retrieval(ComponentBase, ABC):
|
|||||||
if len(kb_vars) > 0:
|
if len(kb_vars) > 0:
|
||||||
for kb_var in kb_vars:
|
for kb_var in kb_vars:
|
||||||
if len(kb_var) == 1:
|
if len(kb_var) == 1:
|
||||||
kb_ids.append(str(kb_var["content"][0]))
|
kb_var_value = str(kb_var["content"][0])
|
||||||
|
|
||||||
|
for v in kb_var_value.split(","):
|
||||||
|
kb_ids.append(v)
|
||||||
else:
|
else:
|
||||||
for v in kb_var.to_dict("records"):
|
for v in kb_var.to_dict("records"):
|
||||||
kb_ids.append(v["content"])
|
kb_ids.append(v["content"])
|
||||||
@ -91,20 +94,24 @@ class Retrieval(ComponentBase, ABC):
|
|||||||
rerank_mdl = LLMBundle(kbs[0].tenant_id, LLMType.RERANK, self._param.rerank_id)
|
rerank_mdl = LLMBundle(kbs[0].tenant_id, LLMType.RERANK, self._param.rerank_id)
|
||||||
|
|
||||||
if kbs:
|
if kbs:
|
||||||
kbinfos = settings.retrievaler.retrieval(query, embd_mdl, kbs[0].tenant_id, filtered_kb_ids,
|
kbinfos = settings.retrievaler.retrieval(
|
||||||
1, self._param.top_n,
|
query,
|
||||||
self._param.similarity_threshold, 1 - self._param.keywords_similarity_weight,
|
embd_mdl,
|
||||||
aggs=False, rerank_mdl=rerank_mdl,
|
kbs[0].tenant_id,
|
||||||
rank_feature=label_question(query, kbs))
|
filtered_kb_ids,
|
||||||
|
1,
|
||||||
|
self._param.top_n,
|
||||||
|
self._param.similarity_threshold,
|
||||||
|
1 - self._param.keywords_similarity_weight,
|
||||||
|
aggs=False,
|
||||||
|
rerank_mdl=rerank_mdl,
|
||||||
|
rank_feature=label_question(query, kbs),
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
kbinfos = {"chunks": [], "doc_aggs": []}
|
kbinfos = {"chunks": [], "doc_aggs": []}
|
||||||
|
|
||||||
if self._param.use_kg and kbs:
|
if self._param.use_kg and kbs:
|
||||||
ck = settings.kg_retrievaler.retrieval(query,
|
ck = settings.kg_retrievaler.retrieval(query, [kbs[0].tenant_id], filtered_kb_ids, embd_mdl, LLMBundle(kbs[0].tenant_id, LLMType.CHAT))
|
||||||
[kbs[0].tenant_id],
|
|
||||||
filtered_kb_ids,
|
|
||||||
embd_mdl,
|
|
||||||
LLMBundle(kbs[0].tenant_id, LLMType.CHAT))
|
|
||||||
if ck["content_with_weight"]:
|
if ck["content_with_weight"]:
|
||||||
kbinfos["chunks"].insert(0, ck)
|
kbinfos["chunks"].insert(0, ck)
|
||||||
|
|
||||||
@ -123,5 +130,3 @@ class Retrieval(ComponentBase, ABC):
|
|||||||
df = pd.DataFrame({"content": kb_prompt(kbinfos, 200000), "chunks": json.dumps(kbinfos["chunks"])})
|
df = pd.DataFrame({"content": kb_prompt(kbinfos, 200000), "chunks": json.dumps(kbinfos["chunks"])})
|
||||||
logging.debug("{} {}".format(query, df))
|
logging.debug("{} {}".format(query, df))
|
||||||
return df.dropna()
|
return df.dropna()
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,13 +10,17 @@ import { FormControl, FormField, FormItem, FormLabel } from './ui/form';
|
|||||||
import { MultiSelect } from './ui/multi-select';
|
import { MultiSelect } from './ui/multi-select';
|
||||||
|
|
||||||
interface KnowledgeBaseItemProps {
|
interface KnowledgeBaseItemProps {
|
||||||
|
label?: string;
|
||||||
tooltipText?: string;
|
tooltipText?: string;
|
||||||
|
name?: string;
|
||||||
required?: boolean;
|
required?: boolean;
|
||||||
onChange?(): void;
|
onChange?(): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const KnowledgeBaseItem = ({
|
const KnowledgeBaseItem = ({
|
||||||
|
label,
|
||||||
tooltipText,
|
tooltipText,
|
||||||
|
name,
|
||||||
required = true,
|
required = true,
|
||||||
onChange,
|
onChange,
|
||||||
}: KnowledgeBaseItemProps) => {
|
}: KnowledgeBaseItemProps) => {
|
||||||
@ -40,8 +44,8 @@ const KnowledgeBaseItem = ({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Form.Item
|
<Form.Item
|
||||||
label={t('knowledgeBases')}
|
label={label || t('knowledgeBases')}
|
||||||
name="kb_ids"
|
name={name || 'kb_ids'}
|
||||||
tooltip={tooltipText || t('knowledgeBasesTip')}
|
tooltip={tooltipText || t('knowledgeBasesTip')}
|
||||||
rules={[
|
rules={[
|
||||||
{
|
{
|
||||||
|
@ -56,6 +56,7 @@ import upperFirst from 'lodash/upperFirst';
|
|||||||
import {
|
import {
|
||||||
CirclePower,
|
CirclePower,
|
||||||
CloudUpload,
|
CloudUpload,
|
||||||
|
Database,
|
||||||
IterationCcw,
|
IterationCcw,
|
||||||
ListOrdered,
|
ListOrdered,
|
||||||
OptionIcon,
|
OptionIcon,
|
||||||
@ -2949,6 +2950,7 @@ export enum BeginQueryType {
|
|||||||
File = 'file',
|
File = 'file',
|
||||||
Integer = 'integer',
|
Integer = 'integer',
|
||||||
Boolean = 'boolean',
|
Boolean = 'boolean',
|
||||||
|
KnowledgeBases = 'kb',
|
||||||
}
|
}
|
||||||
|
|
||||||
export const BeginQueryTypeIconMap = {
|
export const BeginQueryTypeIconMap = {
|
||||||
@ -2958,6 +2960,7 @@ export const BeginQueryTypeIconMap = {
|
|||||||
[BeginQueryType.File]: CloudUpload,
|
[BeginQueryType.File]: CloudUpload,
|
||||||
[BeginQueryType.Integer]: ListOrdered,
|
[BeginQueryType.Integer]: ListOrdered,
|
||||||
[BeginQueryType.Boolean]: ToggleLeft,
|
[BeginQueryType.Boolean]: ToggleLeft,
|
||||||
|
[BeginQueryType.KnowledgeBases]: Database,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const NoDebugOperatorsList = [
|
export const NoDebugOperatorsList = [
|
||||||
|
@ -25,6 +25,7 @@ import { BeginQuery } from '../interface';
|
|||||||
import { PopoverForm } from './popover-form';
|
import { PopoverForm } from './popover-form';
|
||||||
|
|
||||||
import styles from './index.less';
|
import styles from './index.less';
|
||||||
|
import KnowledgeBaseItem from '@/components/knowledge-base-item';
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
parameters: BeginQuery[];
|
parameters: BeginQuery[];
|
||||||
@ -164,6 +165,13 @@ const DebugContent = ({
|
|||||||
<Switch></Switch>
|
<Switch></Switch>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
),
|
),
|
||||||
|
[BeginQueryType.KnowledgeBases]: (
|
||||||
|
<KnowledgeBaseItem
|
||||||
|
name={idx.toString()}
|
||||||
|
label={q.name || q.key}
|
||||||
|
required={!q.optional}
|
||||||
|
></KnowledgeBaseItem>
|
||||||
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -182,6 +190,9 @@ const DebugContent = ({
|
|||||||
if (Array.isArray(value)) {
|
if (Array.isArray(value)) {
|
||||||
nextValue = ``;
|
nextValue = ``;
|
||||||
|
|
||||||
|
if (item.type === 'kb') {
|
||||||
|
nextValue = value.join(',')
|
||||||
|
} else {
|
||||||
value.forEach((x) => {
|
value.forEach((x) => {
|
||||||
nextValue +=
|
nextValue +=
|
||||||
x?.originFileObj instanceof File
|
x?.originFileObj instanceof File
|
||||||
@ -189,6 +200,7 @@ const DebugContent = ({
|
|||||||
: `${x.url}\n${x.result}\n----\n`;
|
: `${x.url}\n${x.result}\n----\n`;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return { ...item, value: nextValue };
|
return { ...item, value: nextValue };
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user