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

[fix] Metadata field is unused when semantic splitter used #104

Merged
merged 1 commit into from
Apr 30, 2024
Merged
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
2 changes: 1 addition & 1 deletion service/embedding.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ async def generate_chunks(
min_split_tokens=config.splitter.min_tokens,
max_split_tokens=config.splitter.max_tokens,
)
chunks = await splitter_config(elements=elements)
chunks = await splitter_config(elements=elements, file=file)

if not chunks:
continue
Expand Down
20 changes: 16 additions & 4 deletions service/splitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from utils.logger import logger
from utils.table_parser import TableParser
from models.file import File


# TODO: Move to document processing utils, once we have
Expand Down Expand Up @@ -125,7 +126,11 @@ def _group_elements_by_title(self, elements: list[dict[str, Any]]) -> dict:
return grouped_elements

async def split_grouped_elements(
self, elements: list[dict[str, Any]], splitter: RollingWindowSplitter
self,
*,
elements: list[dict[str, Any]],
file: File,
splitter: RollingWindowSplitter,
) -> list[dict[str, Any]]:
grouped_elements = self._group_elements_by_title(elements)
chunks_with_title = []
Expand All @@ -138,7 +143,10 @@ def _append_chunks(
"title": title,
"content": content,
"chunk_index": chunk_index,
"metadata": metadata,
"metadata": {
**file.metadata,
**metadata,
},
}
)

Expand Down Expand Up @@ -207,5 +215,9 @@ def _append_chunks(
chunks_with_title.extend(chunks)
return chunks_with_title

async def __call__(self, elements: list[dict[str, Any]]) -> list[dict[str, Any]]:
return await self.split_grouped_elements(elements, self.splitter)
async def __call__(
self, elements: list[dict[str, Any]], file: File
) -> list[dict[str, Any]]:
return await self.split_grouped_elements(
elements=elements, file=file, splitter=self.splitter
)