haystack icon indicating copy to clipboard operation
haystack copied to clipboard

Expand the functionality of the `DocumentCleaner`

Open sjrl opened this issue 10 months ago • 1 comments

Is your feature request related to a problem? Please describe. We've found in practice that cleaning up files before being used in RAG pipelines does increase overall performance. For example, this Haystack user found the same.

We do have a DocumentCleaner to help with this process, but we found there are some options missing for the type of cleaning we would like to accomplish.

Describe the solution you'd like The options I'd like to add to the DocumentCleaner are:

  • an option that just runs .strip() on the content of every document. Often times we just want to remove the extra leading and trailing white space, but leave the white space within a chunk alone. For example, in mark down files the extra newlines can matter for formatting.
  • also an option to provide a regex pattern to remove and a string to replace that regex match with. We currently have a few regex replaces in the DocumentCleaner and have the remove_regex parameter, but we don't have a way to customize what string should be used to replace the regex match. For example, one scenario that I'd like to do is replace all double newline characters \n\n with a single newline character \n.

Describe alternatives you've considered We can create a custom component do perform these operations instead.

sjrl avatar Feb 03 '25 12:02 sjrl

There was a slightly related question on GitHub about passing multiple regular expressions to remove_regex: https://github.com/deepset-ai/haystack/discussions/8899

julian-risch avatar Feb 24 '25 12:02 julian-risch