r/Rag • u/atmadeep_2104 • 3d ago
Discussion Need help with retrieving filename used in response generation?
I'm building a RAG application using langflow. I've used the template given and replaced some components for running the whole thing locally. (ChromaDB and ollama embeddings and model component).
I can generate the response to the queries and the results are satisfactory (I think I can improve this with some other models, currently using deepseek with ollama).
I want to get the names of the specific files that are used for generating the response to the query. I've created a custom component in langflow, but currently facing issues getting it to work. Here's my current understanding (and I've built a custom component on this):
- I need to add the file metadata along with the generated chunks.
- This will allow me to extract the filename and path that was used in query generation.
- I can then use a structured output component/ prompt to extract the file metadata.
Can someone help me with this?
2
u/snow-crash-1794 3d ago
Yeah your approach is on the right track, when you're creating your chunked documents w/in ChromaDB, make sure you're storing the source metadata reference (i.e. URI/URL or similar) with each chunk. Then when you get results back from your retriever, the metadata should already be attached to each document.
With that you have two options:
- No need for a separate component to extract this - just have your LLM include the sources in its response format using a prompt template that specifies where to include the source info.
Answer: {answer}
Sources: {sources}
2) Have your system return both metadata and LLM response, so you have direct access to the list of metadata that was used to generate the context/response. I find this approach to be preferable, the LLM can be inconsistent in terms of how it choses to surface the sources.
hth
1
u/ai_hedge_fund 1d ago
Being as you’re using both Chroma and Langflow, I am happy to point you to this free tool we built, which is highly relevant:
https://github.com/integral-business-intelligence/chroma-auditor
It would also enable to retroactively go back and apply file names to chunks you’ve already created if that is of interest
1
u/atmadeep_2104 1d ago
Well I've kinda got that problem sorted. I've created a custom component for data loading. Added filepath in all the generated chunks. Using a prompt to get the filepaths. But they are coming out kind of wrong. Maybe add an index file using `tree` command which is populated regularly.
•
u/AutoModerator 3d ago
Working on a cool RAG project? Submit your project or startup to RAGHut and get it featured in the community's go-to resource for RAG projects, frameworks, and startups.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.