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

Aperta Adatta ai principianti
#14,081 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@pinjun99 ci sta già lavorando.

Dal 4/12/2026.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
74/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
backend, data

Direzione di ricerca

Inizia leggendo ByteStream.from_file_path e i relativi test; l’issue non indica i loro percorsi, quindi individuali nel repository. Controlla come il metodo combina meta fornito da chi lo chiama con il percorso, quindi confronta il comportamento del convertitore con quanto descritto nell’issue. Il lavoro è completo quando gli stream creati da percorsi includono file_path per impostazione predefinita, meta["file_path"] esplicito viene preservato e i test coprono entrambi i casi.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Python
Stelle
27.2k
Fork
3.5k
Merge medio
1g 18h
PR unite (30g)
254

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di deepset-ai/haystack

Tutte le issue di deepset-ai/haystack

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.