Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵月辉
/
fastgpt-migrated
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Unverified
Commit
933c3fdf
authored
Nov 26, 2023
by
Archer
Committed by
GitHub
Nov 26, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add mongo index (#519)
parent
f8182607
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
52 additions
and
22 deletions
+52
-22
packages/service/common/mongo/init.ts
+3
-3
packages/service/core/dataset/collection/schema.ts
+1
-0
packages/service/core/dataset/data/schema.ts
+2
-1
projects/app/src/pages/api/core/app/form2Modules/fastgpt-universal.ts
+4
-4
projects/app/src/pages/app/detail/components/SimpleEdit/index.tsx
+1
-1
projects/app/src/service/core/dataset/data/pg.ts
+40
-12
projects/app/src/web/core/app/templates.ts
+1
-1
No files found.
packages/service/common/mongo/init.ts
View file @
933c3fdf
...
@@ -26,9 +26,9 @@ export async function connectMongo({
...
@@ -26,9 +26,9 @@ export async function connectMongo({
bufferCommands
:
true
,
bufferCommands
:
true
,
maxConnecting
:
Number
(
process
.
env
.
DB_MAX_LINK
||
5
),
maxConnecting
:
Number
(
process
.
env
.
DB_MAX_LINK
||
5
),
maxPoolSize
:
Number
(
process
.
env
.
DB_MAX_LINK
||
5
),
maxPoolSize
:
Number
(
process
.
env
.
DB_MAX_LINK
||
5
),
minPoolSize
:
2
,
minPoolSize
:
Number
(
process
.
env
.
DB_MAX_LINK
||
10
)
*
0.5
,
connectTimeoutMS
:
2
0000
,
connectTimeoutMS
:
6
0000
,
waitQueueTimeoutMS
:
2
0000
waitQueueTimeoutMS
:
6
0000
});
});
console
.
log
(
'mongo connected'
);
console
.
log
(
'mongo connected'
);
...
...
packages/service/core/dataset/collection/schema.ts
View file @
933c3fdf
...
@@ -69,6 +69,7 @@ const DatasetCollectionSchema = new Schema({
...
@@ -69,6 +69,7 @@ const DatasetCollectionSchema = new Schema({
try
{
try
{
DatasetCollectionSchema
.
index
({
datasetId
:
1
});
DatasetCollectionSchema
.
index
({
datasetId
:
1
});
DatasetCollectionSchema
.
index
({
datasetId
:
1
,
parentId
:
1
});
DatasetCollectionSchema
.
index
({
updateTime
:
-
1
});
DatasetCollectionSchema
.
index
({
updateTime
:
-
1
});
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
log
(
error
);
console
.
log
(
error
);
...
...
packages/service/core/dataset/data/schema.ts
View file @
933c3fdf
...
@@ -78,7 +78,8 @@ try {
...
@@ -78,7 +78,8 @@ try {
DatasetDataSchema
.
index
({
datasetId
:
1
});
DatasetDataSchema
.
index
({
datasetId
:
1
});
DatasetDataSchema
.
index
({
collectionId
:
1
});
DatasetDataSchema
.
index
({
collectionId
:
1
});
// full text index
// full text index
DatasetDataSchema
.
index
({
fullTextToken
:
'text'
});
DatasetDataSchema
.
index
({
datasetId
:
1
,
fullTextToken
:
'text'
});
DatasetDataSchema
.
index
({
fullTextToken
:
1
});
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
log
(
error
);
console
.
log
(
error
);
}
}
...
...
projects/app/src/pages/api/core/app/form2Modules/fastgpt-universal.ts
View file @
933c3fdf
...
@@ -283,21 +283,21 @@ function datasetTemplate(formData: AppSimpleEditFormType): ModuleItemType[] {
...
@@ -283,21 +283,21 @@ function datasetTemplate(formData: AppSimpleEditFormType): ModuleItemType[] {
value
:
formData
.
dataset
.
datasets
,
value
:
formData
.
dataset
.
datasets
,
type
:
FlowNodeInputTypeEnum
.
custom
,
type
:
FlowNodeInputTypeEnum
.
custom
,
label
:
'关联的知识库'
,
label
:
'关联的知识库'
,
connected
:
tru
e
connected
:
fals
e
},
},
{
{
key
:
'similarity'
,
key
:
'similarity'
,
value
:
formData
.
dataset
.
similarity
,
value
:
formData
.
dataset
.
similarity
,
type
:
FlowNodeInputTypeEnum
.
slider
,
type
:
FlowNodeInputTypeEnum
.
slider
,
label
:
'相似度'
,
label
:
'相似度'
,
connected
:
tru
e
connected
:
fals
e
},
},
{
{
key
:
'limit'
,
key
:
'limit'
,
value
:
formData
.
dataset
.
limit
,
value
:
formData
.
dataset
.
limit
,
type
:
FlowNodeInputTypeEnum
.
slider
,
type
:
FlowNodeInputTypeEnum
.
slider
,
label
:
'单次搜索上限'
,
label
:
'单次搜索上限'
,
connected
:
tru
e
connected
:
fals
e
},
},
{
{
key
:
'switch'
,
key
:
'switch'
,
...
@@ -317,7 +317,7 @@ function datasetTemplate(formData: AppSimpleEditFormType): ModuleItemType[] {
...
@@ -317,7 +317,7 @@ function datasetTemplate(formData: AppSimpleEditFormType): ModuleItemType[] {
label
:
'结果重排'
,
label
:
'结果重排'
,
description
:
'将召回的结果进行进一步重排,可增加召回率'
,
description
:
'将召回的结果进行进一步重排,可增加召回率'
,
plusField
:
true
,
plusField
:
true
,
connected
:
tru
e
,
connected
:
fals
e
,
value
:
formData
.
dataset
.
rerank
value
:
formData
.
dataset
.
rerank
}
}
],
],
...
...
projects/app/src/pages/app/detail/components/SimpleEdit/index.tsx
View file @
933c3fdf
...
@@ -392,7 +392,7 @@ function ConfigForm({
...
@@ -392,7 +392,7 @@ function ConfigForm({
})
})
}
}
>
>
<
Image
alt=
{
''
}
src=
{
item
.
avatar
}
w=
{
'18px'
}
mr=
{
1
}
/>
<
Avatar
src=
{
item
.
avatar
}
w=
{
'18px'
}
mr=
{
1
}
/>
<
Box
flex=
{
'1 0 0'
}
w=
{
0
}
className=
{
'textEllipsis'
}
fontSize=
{
'sm'
}
>
<
Box
flex=
{
'1 0 0'
}
w=
{
0
}
className=
{
'textEllipsis'
}
fontSize=
{
'sm'
}
>
{
item
.
name
}
{
item
.
name
}
</
Box
>
</
Box
>
...
...
projects/app/src/service/core/dataset/data/pg.ts
View file @
933c3fdf
import
{
PgDatasetTableName
}
from
'@fastgpt/global/core/dataset/constant'
;
import
{
PgDatasetTableName
}
from
'@fastgpt/global/core/dataset/constant'
;
import
type
{
import
type
{
DatasetData
WithCollection
Type
,
DatasetData
Schema
Type
,
SearchDataResponseItemType
SearchDataResponseItemType
}
from
'@fastgpt/global/core/dataset/type.d'
;
}
from
'@fastgpt/global/core/dataset/type.d'
;
import
{
PgClient
}
from
'@fastgpt/service/common/pg'
;
import
{
PgClient
}
from
'@fastgpt/service/common/pg'
;
...
@@ -298,30 +298,58 @@ export async function fullTextRecall({
...
@@ -298,30 +298,58 @@ export async function fullTextRecall({
};
};
}
}
const
result
=
(
await
MongoDatasetData
.
find
(
let
searchResults
=
(
await
Promise
.
all
(
datasetIds
.
map
((
id
)
=>
MongoDatasetData
.
find
(
{
{
datasetId
:
{
$in
:
datasetIds
.
map
((
item
)
=>
item
)
}
,
datasetId
:
id
,
$text
:
{
$search
:
jiebaSplit
({
text
})
}
$text
:
{
$search
:
jiebaSplit
({
text
})
}
},
},
{
score
:
{
$meta
:
'textScore'
}
}
{
score
:
{
$meta
:
'textScore'
},
_id
:
1
,
datasetId
:
1
,
collectionId
:
1
,
q
:
1
,
a
:
1
,
indexes
:
1
}
)
)
.
sort
({
score
:
{
$meta
:
'textScore'
}
})
.
sort
({
score
:
{
$meta
:
'textScore'
}
})
.
limit
(
limit
)
.
limit
(
limit
)
.
populate
(
'collectionId'
)
.
lean
()
.
lean
())
as
DatasetDataWithCollectionType
[];
)
)
).
flat
()
as
(
DatasetDataSchemaType
&
{
score
:
number
})[];
// resort
searchResults
.
sort
((
a
,
b
)
=>
b
.
score
-
a
.
score
);
searchResults
.
slice
(
0
,
limit
);
const
collections
=
await
MongoDatasetCollection
.
find
(
{
_id
:
{
$in
:
searchResults
.
map
((
item
)
=>
item
.
collectionId
)
}
},
'_id name metadata'
);
return
{
return
{
fullTextRecallResults
:
result
.
map
((
item
)
=>
({
fullTextRecallResults
:
searchResults
.
map
((
item
)
=>
{
const
collection
=
collections
.
find
((
col
)
=>
String
(
col
.
_id
)
===
String
(
item
.
collectionId
));
return
{
id
:
String
(
item
.
_id
),
id
:
String
(
item
.
_id
),
datasetId
:
String
(
item
.
datasetId
),
datasetId
:
String
(
item
.
datasetId
),
collectionId
:
String
(
item
.
collectionId
.
_i
d
),
collectionId
:
String
(
item
.
collectionI
d
),
sourceName
:
item
.
collectionId
.
name
||
''
,
sourceName
:
collection
?
.
name
||
''
,
sourceId
:
item
.
collectionId
.
metadata
?.
fileId
||
item
.
collectionId
.
metadata
?.
rawLink
,
sourceId
:
collection
?.
metadata
?.
fileId
||
collection
?
.
metadata
?.
rawLink
,
q
:
item
.
q
,
q
:
item
.
q
,
a
:
item
.
a
,
a
:
item
.
a
,
indexes
:
item
.
indexes
,
indexes
:
item
.
indexes
,
score
:
1
// @ts-ignore
})),
score
:
item
.
score
};
}),
tokenLen
:
0
tokenLen
:
0
};
};
}
}
...
...
projects/app/src/web/core/app/templates.ts
View file @
933c3fdf
...
@@ -225,7 +225,7 @@ export const appTemplates: (AppItemType & {
...
@@ -225,7 +225,7 @@ export const appTemplates: (AppItemType & {
]
]
},
},
{
{
id
:
'simple
Kb
Chat'
,
id
:
'simple
Dataset
Chat'
,
avatar
:
'/imgs/module/db.png'
,
avatar
:
'/imgs/module/db.png'
,
name
:
'知识库 + 对话引导'
,
name
:
'知识库 + 对话引导'
,
intro
:
'每次提问时进行一次知识库搜索,将搜索结果注入 LLM 模型进行参考回答'
,
intro
:
'每次提问时进行一次知识库搜索,将搜索结果注入 LLM 模型进行参考回答'
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment