Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LlamaIndexTS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
MachineLearning
run-llama
LlamaIndexTS
Commits
645fcf6c
Unverified
Commit
645fcf6c
authored
10 months ago
by
ezirmusitua
Committed by
GitHub
10 months ago
Browse files
Options
Downloads
Patches
Plain Diff
fix: use sha256 hash value as the `Document.id_` in `MarkdownReader` (#768)
Co-authored-by:
Alex Yang
<
himself65@outlook.com
>
parent
e37fa5d9
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
packages/core/src/readers/MarkdownReader.ts
+6
-6
6 additions, 6 deletions
packages/core/src/readers/MarkdownReader.ts
packages/core/src/readers/PDFReader.ts
+4
-8
4 additions, 8 deletions
packages/core/src/readers/PDFReader.ts
with
10 additions
and
14 deletions
packages/core/src/readers/MarkdownReader.ts
+
6
−
6
View file @
645fcf6c
...
...
@@ -95,16 +95,16 @@ export class MarkdownReader implements FileReader {
const
content
=
await
fs
.
readFile
(
file
);
const
tups
=
this
.
parseTups
(
content
);
const
results
:
Document
[]
=
[];
let
counter
=
0
;
for
(
const
[
header
,
value
]
of
tups
)
{
const
id_
=
`
${
file
}
_
${
counter
}
`
;
if
(
header
)
{
results
.
push
(
new
Document
({
text
:
`\n\n
${
header
}
\n
${
value
}
`
,
}),
);
const
text
=
`\n\n
${
header
}
\n
${
value
}
`
;
results
.
push
(
new
Document
({
text
,
id_
}));
}
else
{
results
.
push
(
new
Document
({
text
:
value
}));
results
.
push
(
new
Document
({
text
:
value
,
id_
}));
}
counter
+=
1
;
}
return
results
;
}
...
...
This diff is collapsed.
Click to expand it.
packages/core/src/readers/PDFReader.ts
+
4
−
8
View file @
645fcf6c
import
type
{
GenericFileSystem
}
from
"
@llamaindex/env
"
;
import
{
createSHA256
,
defaultFS
}
from
"
@llamaindex/env
"
;
import
{
defaultFS
}
from
"
@llamaindex/env
"
;
import
{
Document
}
from
"
../Node.js
"
;
import
type
{
BaseReader
}
from
"
./type.js
"
;
...
...
@@ -13,13 +13,9 @@ export class PDFReader implements BaseReader {
):
Promise
<
Document
[]
>
{
const
content
=
await
fs
.
readRawFile
(
file
);
const
text
=
await
readPDF
(
content
);
return
text
.
map
((
text
)
=>
{
const
sha256
=
createSHA256
();
sha256
.
update
(
text
);
return
new
Document
({
text
,
id_
:
sha256
.
digest
(),
});
return
text
.
map
((
text
,
page
)
=>
{
const
id_
=
`
${
file
}
_
${
page
}
`
;
return
new
Document
({
text
,
id_
});
});
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment