feat: `ByteStream.from_file_path` should keep the file path in `meta`

Abierto Apto para principiantes
#14,081 3 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@pinjun99 ya está trabajando en esto.

Desde el 4/12/2026.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
74/100
Tipo de issue
Nueva funcionalidad
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
python
Área
backend, data

Línea de trabajo

Empieza leyendo ByteStream.from_file_path y sus pruebas; el issue no indica sus rutas de archivo, así que localízalas en el repositorio. Comprueba cómo combina el método meta proporcionado por quien lo llama con la ruta y, después, compara el comportamiento del conversor con lo descrito en el issue. El trabajo estará terminado cuando los streams creados a partir de rutas incluyan file_path de forma predeterminada, se conserve el meta["file_path"] explícito y las pruebas cubran ambos casos.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Is your feature request related to a problem? Please describe.

I was playing with a small RAG pipeline on Windows. Most of my text files are UTF-8, but one is an older file saved in cp1252. To give just that one file its own encoding, I loaded it with ByteStream.from_file_path(path, meta={"encoding": "cp1252"}) and passed it to TextFileToDocument together with the other paths.

The encoding part worked nicely, but I noticed that document had no file_path in its meta, while all the others did. In a RAG app that's usually what you show as the source of an answer, so that one document quietly lost its source.

Here's a minimal example:

from pathlib import Path
from haystack.components.converters import TextFileToDocument
from haystack.dataclasses import ByteStream

path = Path("notes.txt")
path.write_text("Some notes.", encoding="utf-8")

converter = TextFileToDocument()

# From a path: file_path is set
print(converter.run(sources=[path])["documents"][0].meta)
# {'file_path': 'notes.txt'}

# From ByteStream.from_file_path: file_path is missing
stream = ByteStream.from_file_path(path)
print(converter.run(sources=[stream])["documents"][0].meta)
# {}

Describe the solution you'd like

It would be great if ByteStream.from_file_path added file_path to meta on its own. If someone already passes their own file_path in meta, theirs should win. Converters already shorten it to just the file name when store_full_path=False, so documents would end up with the same metadata whether they came from a path or a ByteStream.

Describe alternatives you've considered

Right now I can pass it myself: meta={"encoding": "cp1252", "file_path": str(path)}. That works, but it's easy to forget, and nothing tells you when you do.

Additional context

Haystack itself does this by hand right after calling from_file_path, in two places:

  • get_bytestream_from_source in haystack/components/converters/utils.py: bs.meta["file_path"] = str(source)
  • haystack/components/converters/image/image_utils.py: ByteStream.from_file_path(pdf_path, meta={"file_path": str(pdf_path)})

Also, the similar FileContent.from_file_path already keeps the file name (filename = filename or file_path.name), so this would make the two behave the same way.

If this sounds reasonable, I'd be happy to open a PR with the change and tests.

Tested on main (3.6.0-rc0), Windows 11, Python 3.14.

Lenguaje dominante
Python
Estrellas
27.2k
Forks
3.5k
Merge medio
1 d 18 h
PR fusionados (30 d)
254

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de deepset-ai/haystack

Todos los issues de deepset-ai/haystack

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.