Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: megaparse in registry + chunk_size #3470

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions core/quivr_core/processor/implementations/megaparse_processor.py
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why ? If we have a small text better not to chunk no ?
I wanted to change it to:

if len(response["result"]) > self.splitter_config.chunk_size:
            docs = self.text_splitter.split_documents([document])
            for doc in docs:
                doc.metadata = {"chunk_size": len(self.enc.encode(doc.page_content))}
            return docs
        return [document]

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I agree with @chloedia

Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ async def process_file_inner(self, file: QuivrFile) -> list[Document]:
document = Document(
page_content=response["result"],
)
if len(response) > self.splitter_config.chunk_size:
docs = self.text_splitter.split_documents([document])
for doc in docs:
doc.metadata = {"chunk_size": len(self.enc.encode(doc.page_content))}
return docs
return [document]
docs = self.text_splitter.split_documents([document])
for doc in docs:
doc.metadata = {"chunk_size": len(self.enc.encode(doc.page_content))}
return docs
53 changes: 27 additions & 26 deletions core/quivr_core/processor/registry.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import importlib
import logging
from os import getenv
import types
from dataclasses import dataclass, field
from heapq import heappop, heappush
Expand Down Expand Up @@ -119,32 +120,32 @@ def defaults_to_proc_entries(
priority=None,
)

# TODO(@aminediro): Megaparse should register itself
# Append Megaparse
_append_proc_mapping(
mapping=base_processors,
file_exts=[
FileExtension.pdf,
FileExtension.docx,
FileExtension.doc,
FileExtension.pptx,
FileExtension.xls,
FileExtension.xlsx,
FileExtension.csv,
FileExtension.epub,
FileExtension.bib,
FileExtension.odt,
FileExtension.html,
FileExtension.py,
FileExtension.markdown,
FileExtension.md,
FileExtension.mdx,
FileExtension.ipynb,
],
cls_mod="quivr_core.processor.implementations.megaparse_processor.MegaparseProcessor",
errtxt=f"can't import MegaparseProcessor. Please install quivr-core[{ext_str}] to access MegaparseProcessor",
priority=None,
)
# TODO(@aminediro @chloedia): Megaparse should register itself
if getenv("MEGAPARSE_URL") and getenv("MEGAPARSE_API_KEY"):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tha aws url for megaparse is defaulted in MegaParseSDK, so you just need to check API and even then, what if we want to run megaparse API locally -> we force api key?

_append_proc_mapping(
mapping=base_processors,
file_exts=[
FileExtension.pdf,
FileExtension.docx,
FileExtension.doc,
FileExtension.pptx,
FileExtension.xls,
FileExtension.xlsx,
FileExtension.csv,
FileExtension.epub,
FileExtension.bib,
FileExtension.odt,
FileExtension.html,
FileExtension.py,
FileExtension.markdown,
FileExtension.md,
FileExtension.mdx,
FileExtension.ipynb,
],
cls_mod="quivr_core.processor.implementations.megaparse_processor.MegaparseProcessor",
errtxt=f"can't import MegaparseProcessor. Please install quivr-core[{ext_str}] to access MegaparseProcessor",
priority=None,
)
return base_processors


Expand Down
Loading