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
05611df0
authored
Jun 12, 2024
by
Archer
Committed by
GitHub
Jun 12, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perf: vector generate (#1748)
parent
d0085a23
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
47 deletions
+47
-47
projects/app/src/pages/api/core/dataset/training/rebuildEmbedding.ts
+15
-4
projects/app/src/service/events/generateVector.ts
+32
-43
No files found.
projects/app/src/pages/api/core/dataset/training/rebuildEmbedding.ts
View file @
05611df0
...
@@ -81,14 +81,18 @@ async function handler(
...
@@ -81,14 +81,18 @@ async function handler(
});
});
// get 10 init dataset.data
// get 10 init dataset.data
const
arr
=
new
Array
(
10
).
fill
(
0
);
const
max
=
global
.
systemEnv
?.
vectorMaxProcess
||
10
;
const
arr
=
new
Array
(
max
*
2
).
fill
(
0
);
for
await
(
const
_
of
arr
)
{
for
await
(
const
_
of
arr
)
{
await
mongoSessionRun
(
async
(
session
)
=>
{
try
{
const
hasNext
=
await
mongoSessionRun
(
async
(
session
)
=>
{
// get next dataset.data
const
data
=
await
MongoDatasetData
.
findOneAndUpdate
(
const
data
=
await
MongoDatasetData
.
findOneAndUpdate
(
{
{
rebuilding
:
true
,
teamId
,
teamId
,
datasetId
,
datasetId
rebuilding
:
true
},
},
{
{
$unset
:
{
$unset
:
{
...
@@ -124,7 +128,14 @@ async function handler(
...
@@ -124,7 +128,14 @@ async function handler(
}
}
);
);
}
}
return
!!
data
;
});
});
if
(
!
hasNext
)
{
break
;
}
}
catch
(
error
)
{}
}
}
return
{};
return
{};
...
...
projects/app/src/service/events/generateVector.ts
View file @
05611df0
...
@@ -158,43 +158,8 @@ const rebuildData = async ({
...
@@ -158,43 +158,8 @@ const rebuildData = async ({
const
deleteVectorIdList
=
mongoData
.
indexes
.
map
((
index
)
=>
index
.
dataId
);
const
deleteVectorIdList
=
mongoData
.
indexes
.
map
((
index
)
=>
index
.
dataId
);
const
{
tokens
}
=
await
mongoSessionRun
(
async
(
session
)
=>
{
// Find next rebuilding data to insert training queue
// update vector, update dataset.data rebuilding status, delete data from training
await
mongoSessionRun
(
async
(
session
)
=>
{
const
updateResult
=
await
Promise
.
all
(
mongoData
.
indexes
.
map
(
async
(
index
,
i
)
=>
{
const
result
=
await
insertDatasetDataVector
({
query
:
index
.
text
,
model
:
getVectorModel
(
trainingData
.
model
),
teamId
:
mongoData
.
teamId
,
datasetId
:
mongoData
.
datasetId
,
collectionId
:
mongoData
.
collectionId
});
mongoData
.
indexes
[
i
].
dataId
=
result
.
insertId
;
return
result
;
})
);
// Ensure that the training data is deleted after the Mongo update is successful
await
mongoData
.
save
({
session
});
await
trainingData
.
deleteOne
({
session
});
// delete old vector
await
deleteDatasetDataVector
({
teamId
:
mongoData
.
teamId
,
idList
:
deleteVectorIdList
});
return
{
tokens
:
updateResult
.
reduce
((
acc
,
cur
)
=>
acc
+
cur
.
tokens
,
0
)
};
});
// find next data insert to training queue
const
arr
=
new
Array
(
5
).
fill
(
0
);
for
await
(
const
_
of
arr
)
{
try
{
const
hasNextData
=
await
mongoSessionRun
(
async
(
session
)
=>
{
// get new mongoData insert to training
// get new mongoData insert to training
const
newRebuildingData
=
await
MongoDatasetData
.
findOneAndUpdate
(
const
newRebuildingData
=
await
MongoDatasetData
.
findOneAndUpdate
(
{
{
...
@@ -232,15 +197,39 @@ const rebuildData = async ({
...
@@ -232,15 +197,39 @@ const rebuildData = async ({
{
session
}
{
session
}
);
);
}
}
});
// update vector, update dataset_data rebuilding status, delete data from training
// 1. Insert new vector to dataset_data
const
updateResult
=
await
Promise
.
all
(
mongoData
.
indexes
.
map
(
async
(
index
,
i
)
=>
{
const
result
=
await
insertDatasetDataVector
({
query
:
index
.
text
,
model
:
getVectorModel
(
trainingData
.
model
),
teamId
:
mongoData
.
teamId
,
datasetId
:
mongoData
.
datasetId
,
collectionId
:
mongoData
.
collectionId
});
mongoData
.
indexes
[
i
].
dataId
=
result
.
insertId
;
return
result
;
})
);
const
{
tokens
}
=
await
mongoSessionRun
(
async
(
session
)
=>
{
// 2. Ensure that the training data is deleted after the Mongo update is successful
await
mongoData
.
save
({
session
});
// 3. Delete the training data
await
trainingData
.
deleteOne
({
session
});
return
!!
newRebuildingData
;
// 4. Delete old vector
await
deleteDatasetDataVector
({
teamId
:
mongoData
.
teamId
,
idList
:
deleteVectorIdList
});
});
if
(
!
hasNextData
)
{
return
{
break
;
tokens
:
updateResult
.
reduce
((
acc
,
cur
)
=>
acc
+
cur
.
tokens
,
0
)
}
};
}
catch
(
error
)
{}
});
}
return
{
tokens
};
return
{
tokens
};
};
};
...
...
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