https://www.boundaryml.com logo
🟑 Developing a natural language research tool for...
# questions
a
Still struggling very much with my flow. I am building a natural language research tool for pubmed articles. Flow is: user gives a query and then I embed it and then search top k from my database to retrieve articles: I want to beside each article show a small summary of it pertaining to the problem. Then after the LLM looks at ALL the articles, I want to generate an answer that cites some of the articles as inline citations. This is how I envision the UI loading: [Answer (would probably stream #3)] [Articles] - The name of article would stream first pretty quickly so I can load that #1 - The summary would likely load next so a bunch of articles would be loading as the next stream of things #2 - Citation (if article cited would be #4) #5 I would then in the UI want to sort the articles by citation number I was trying to go off of this example https://baml-examples.vercel.app/examples/get-recipe and the example with the spacex but others would be welcome. 1) General thoughts about how I might go about this / if my thinking is correct 2) Thoughts on how beefy of a model I might need for this / recs? my intuition is summaries can be done by a small model even 4o or 4o mini but might need a gpt-5 to generate the answer with the numbered citations. 3) Would an llm be better at giving say the article name as a citation as opposed to a numbered citation? I could look it up by id You guys are the absolute best not only giving a good language for us to use but also helping people like me who are new to this space learn. Love BAML!
a
1) I think you're correct mostly yes, hardest part is probably updating the UI with the different parts of each query result because you're not generating the entire result once and streaming it in a single request. Seems like frontend sends query text to backend, backend can return article titles right after, but then process the LLM summaries and answer in the background, and when ready you have to start streaming that. Not sure if you can do it without anything realtime (like Websockets) maybe you can make many different requests, one that returns the titles of the articles as soon as possible, then when you have the titles make another request that streams summaries and answer + citations. Streaming summaries in parallel for each article is more complex and you wouldn't have the LLM look at all the articles at once to generate the answer. 2) I agree summaries don't need any beefy model. The final answer with citations probably doesn't either since it's basically another summary with some references to the provided text, I'd try 4o first and compare some examples with 5 see if it's really that much better. 3) I think it won't make such a big difference because the number is just another way of referencing the article just like the title, you're not asking the LLM to do math, it's still text. I could be wrong though, try out both and see which one yields better results. Testing prompts in Baml is easy. Another thing, showing the titles in the UI then streaming summaries and then an answer, to finally sort the articles would be a little confusing UX. By the time you may want to read an article they automatically sort and you lose track of where it was. Maybe it's better to add a "sort articles by citation" button.
a
@icdev2dev yes similar in the way you have cited it
Thanks so much antonio!
I think @Vaibhav (BAML πŸ‘) mentioned once on a stream that llms are not good at counting these citations so listing the text might be better so it’s not a wrong number associated with a citation
a
I think you can guide the LLM for citations though: I have used code similar to the one below but messing up citations is common for smaller models from my usage so you might need to beef up the model if you are pulling a lot of pubmed articles into context. Those articles are also pretty large.
Copy code
{% for article in articles %}
Article: {{ loop.index }}
{{ article }}
---
{% endfor %}
i
I will opensource this soon