My study agent said "Embedding your PDF :)"
I built StudyWithFriend , a local AI study assistant that lets you drop PDFs into a folder, ask questions, and get answers based on your own notes using RAG (Retrieval-Augmented Generation). Sounds simple, right? Well, it wasn't. The problem In my first version, embedding a PDF would freeze the entire chat. My first solution was to move the embedding process into a separate terminal window. The…
StudyWithFriend is a local AI study assistant that enables users to drop PDFs into a folder, ask questions, and receive answers based on their own notes using Retrieval-Augmented Generation (RAG). The creator built this tool to simplify the process, but encountered several issues in the first version.
The initial problem was that embedding a PDF would freeze the chat entirely. The creator first resolved this by running the embedding process in a separate terminal window, but this introduced a new issue: the AI was no longer answering from the PDFs. After investigating the pipeline, they discovered that the database had 0 chunks, leading to five underlying bugs.
1. The LLM was controlling the embedding process, which shouldn't be an LLM's responsibility. The application should handle background tasks independently.
2. A library change caused the embedding job to crash at the final step, as it was using a deprecated method.
3. The separate terminal window closed immediately after the process completed, leaving no visible error or feedback for debugging.
4. Every PDF generated chunk IDs from 0, 1, 2, etc., causing overwriting issues and resulting in a non-functional knowledge base.
5. The search results displayed negative similarity scores, which were being filtered out, effectively returning no results.
To address these issues, the creator changed the ingestion workflow. Now, the application controls embedding jobs, runs them in the background without blocking the chat, provides status messages, assigns unique chunk IDs, and corrects similarity calculation using cosine similarity.
Interestingly, the creator also discovered an Ollama configuration issue. The num_gpu=1 setting controlled GPU layer offloading, not the number of GPUs, resulting in a 5x performance improvement when the setting was removed.
The end result is that an 8-page PDF is now fully processed and searchable within approximately 3 seconds after being dropped into the folder. The chat remains responsive, ingestion errors are visible, and retrieval functions properly. The creator emphasizes that reliable AI systems require reliable software engineering, not just focusing on the model or AI components.
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to