Back to Index

Chatting with ArXiv Research Papers — AI Assistant #3


Chapters

0:0 LangChain AI Assistant
0:40 New Arxiver bot in Python
6:0 Arxiver LangChain agent code
12:22 Adding new papers to the DB

Transcript

Okay, so today we have an update on the AI Assistant project that we've been working on for a little while. It's kind of been on the back burner for a while with everything else that's been going on, but today I think it's probably the first exciting part of the tool that you can actually use.

And, well, let me just show you what it looks like. So come over to Colab here, I just do the PIP install, the most recent version, so 0.5. And then we set our environment variables, so that's just API keys that we need from OpenAI and Pinecone. And then I come down to here and I initialize, so this is a new thing, this archiver bot, all right?

So initialize that, and this archiver is everything we need to begin interacting with the code library that we've already built in the previous two videos. So the downloading of papers and the search through those papers, that can now, or that will be fully controlled through the chatbot. At the moment, it's just a search that is implemented and kind of in the progress of building the upload part of that as well.

So we can run this and this is a question that is kind of covered in one of the papers that I have added, and it's, what is the general scientific consensus on development tool usage in early hominids? So it's from this paper here on, it's not even a paper, I think it's a chapter of a book on the evolution of intelligence.

Now, I noticed adding like a non, like AI, computer science article into the dataset, that there are a few things with the library that doesn't quite work yet, like references here are mostly not archive papers. And I don't, there might not even be any archive papers in there. So I need to figure out a better way of dealing with that when we're doing like the propagation approach to finding all of the relevant papers.

And I'm not sure how well it's being processed, like the chunks, maybe the size of chunks needs to be increased or decreased. I'm not sure. So let's have a look at this. What did we get? There's a scientific consensus that early hominids developed tool usage with Homo habilis, making tools a long time ago, Homo erectus showing evidence of enhanced intelligence with task-specific stone hand axes.

Okay. So, I mean, this is a pretty good answer, I think. And it also tells me the source, right? So I could ask chatGPT this, and it may or it may not give me a good answer. I think on this sort of topic, it probably would give a decent answer, but I don't know where that information is coming from.

And I don't want to just blindly rely on that. Okay. Especially when you're doing actual research and you need to source what you're talking about, right? So I can click on here and it's going to take us to that paper that we saw before. Okay. And we see it's the evolution of intelligence, which is from a book, I think.

Then, okay. Could you tell me about development tool usage in this context? So it's kind of interesting. They have like the, we have some basic simple stone tools, and then it's talking about stone hand axes. It's kind of cool. So, okay. Tell me more about that. And this does take a little while to run.

Maybe that's something we can try and improve. But I think right now it's kind of a consequence of what is happening. We're like, we're making multiple calls, open AI. And it just, it takes a while to process. Even though we're using, in this case, we're using GPT-3.5 Turbo, which is one of the faster models.

I mean, if you did this with GPT-4, it would take a very long time. But anyway, so, okay. We've got this output they developed. Is this what I want? Sorry. It's a development of tool usage. And I'm kind of asking the same thing. Okay. Let me change that. So let's ask, okay.

Tell me more about those hand axes. Tell me more about these hand axes. Okay. Let's try that. Okay. So it's being specific. Like it knows, I just said these hand axes, but because we have the chat history in there, it knows to actually search for the Homo erectus hand axes, because it can see the previous interactions that we had.

Okay. And the answer is just that. Okay. It doesn't actually tell us much. Okay. And let's see if there's something else that we can have. So there's also evidence of great similarities between humans and great apes. So let's ask about that. So what are the similarities between humans and great apes?

Okay. You can see again, it's creating the search term here. And our answer is similarities between humans and great apes include basic symbolism and creativity, which evolved as an adaption to forested environments of Eurasia during the Miocene. And then evidence of great similarities between humans and great apes and intelligent, in intelligence and traditionally believed has been found the apes ancestors from the mid-late Miocene had brains of comparable size.

So these intellectual capabilities may have been potentiated as early as 12 to 14 million years ago. All right. Okay. So I think the point here is that we probably had like a common ancestor around that time ago. And at that point, we already, you know, the intelligence of humans was already well on its way to becoming what it was now.

Right. Okay. Cool. So that is like the bot interface. Let me talk a little bit more about where this is going. Okay. Okay. So come over to, this is a new code that we have. So this is like the chat interface thing that we're doing. We're using line chain to create all of this.

So we have a few things. So we have a couple of prompts that we're creating here. The initializing function of this class is basically just setting everything up. So initializing the large language model, the memory retrieval component, the chat bot, and also this splitter. So this, we haven't used this yet.

This is when we start uploading documents via this function. So that's something I'll talk about a little bit later. So when we call this function, it just executes, right? So it executes on the agent that we create. So let's have a look at how we actually create those. So first we initialize a large language model.

We can see that here. So that's just a chat model via line chain, gpt 3.5 turbo by default. And then we go on and we initialize our memory. So this is one of the more complicated parts. So the memory, we have this pine cone object, which is actually from here.

Okay. So we have this pine cone class that we created. So we initialize that. We initialize a encoder via a line chain. We initialize a vector DB via line chain. So there's a bit of repetition here. We have this vector DB, and then we also have another version of it here.

Something needs to be cleaned up. This is like the first version that I wrote pretty quickly. And then we have the retriever. So this is a retrieval Q&A with sources chain from line chain. So basically we're going to retrieve relevant documents, and we're also going to include the sources in there.

That's super important. I tried in these prompts to make sure that it's going to include those sources of information all the time. Okay. So that's important. Okay. And then we come down here and we initialize a search tool, right? So this is just one of the tools. There will be multiple tools that the agent can use.

This is just one of them. And it's like the core functionality, which is where we're chatting with the agent, and we want it to refer to these archive papers. Okay. This is how it does it, right? So it uses the search function, which is here. Okay. This is basically just a custom version of the retrieval tool that is already within line chain.

The only difference is that we add in the sources to the answer response or the answer value here, because before it didn't seem to be using this, because you basically get a answer value and a sources value. It didn't seem to be considering the sources value in the final answer.

So I just forced them into the actual answer value here. That's the only difference. I'll probably make some other changes to that in the future, but for now, that's fine. And then, okay. So that's the search function that our tool uses. We have a description, which is the search description here.

So we need to use this tool when searching for scientific research information from our prebuilt archive papers database. This should be the first option when looking for information. When receiving information from this tool, you must always include all sources of information, right? So again, sources of information, super important.

And then we append that tool to our tools list, right? So then that's kind of ready to be used by our agent, okay? And then we initialize our agent. That's the next step here. So the chatbot agent. So that is here, right? So we use the conversational memory. I haven't really messed around so much with this at the moment, but we use conversational buffer window memory.

So we keep basically a track of the last five interactions. And then we forget it, okay? Then we initialize the agent. So we're using the chat conversational react description agent. What that means is that it's for a trap model, which is the GT 2.5 turbo model that we've initialized.

It's conversational, meaning there is this conversational memory considered by the agent. So it's not just looking at a single interaction. It's looking at a history of interactions. The react is like a framework where you are basically saying, I want you to reason about what action to take and then take the action, okay?

So the RE is reason and the act is action, okay? And then description is basically saying, base your decision on whether to use this agent on the agent description, which we defined here, okay? So that is our initialized agent. And then we just update the prompt. So we have this custom system message up here, okay?

Which is your expert summarizer and deliver technical information. You make complex information incredibly simple to understand, so on and so on, okay? I just wrote this quickly. It definitely needs some work. But one thing I did add that again is pretty important is just really telling the agent again and again to include a source of information at the end of responses, okay?

So I just like hammer that in as often as I can just to make sure that it's actually doing that, okay? So after that, we're done, right? So that is the agent, it's created. And then the final bit that is in this initialization component is initialize the extraction tooling.

That is for later that I'm not using that right now, but I will be at some point. And I kind of show you what that is going to look like. So if we come over to here, we have basically the same code we saw before. This is running locally.

So I can like test the most recent version of the bot. So we just asked questions. It's going to do the exact same thing, right? I'm AI language model, right? It's not accessing the database at this point. If I ask you a technical question, it's going to access the database, right?

Okay, cool. Then the next thing that I'm doing here is I want to be able to use this chat interface to add new articles to the database, right? At the moment, we have to use a different script where we manually, not manually, but we write code in order to add those papers to the database.

I don't want to do that. I want to let users interact with the chatbot and say, I would like to talk about this particular paper and for that paper to not be within the database already. And the chatbot know that, okay, if they want to talk about that, we need to search the internet.

We need to retrieve that paper. We need to embed it, add it to the database, and then we can start talking about it, right? I'm not sure because that takes a little bit of time. So at some point there'll need to be some like async code in here, which handles that and then says, okay, you need to give me a bit of time to think about it.

Something like that. I'm not sure yet, but for now it's just creating that, right? So the way that that will be implemented, I'm not a hundred percent sure yet, but I've started doing it. So we have this add article to database function, right? That is just getting the archive ID, basically.

It's using that to download. So this is from constructors, I think. Yes, it's an archive class. Okay, archive class here. This is another function from the library. So that downloads the archive object. Or we get information on it. Then we download it. We get the metadata for the paper, and then we shrink the paper in smaller parts.

So into the like 300 token slices, and then we add that to the database. Okay, right? And then we return, or we're going to return something like this. So we're going to return that saying, I've added this to my memory. It's now accessible via the search archive database tool.

So this is both kind of for the user to see, but also actually more for the chatbot to see. So once it's seen that, okay, we have this in our memory now, we can now access it through this other tool, right? So if it's going through those multiple steps, it can download it, and then it can ask a question to the tool.

Okay? So that is a function. I've tested it here. So I added the attention is all you need paper. You know, that worked. And then I asked the question, and it retrieved the relevant information from that paper. That's kind of what I want to do, but I don't want to write code like this to do it.

I would rather write something like, but can you add the like 1706.03762 paper to your memory? Okay? I want to say something like that, or rather than that, I would like to say, can you add the attention is all you need paper to your memory, or can you add some papers, right?

So this is where we might search for multiple papers, some papers about NLP attention to your memory, right? I want to be able to ask these things to the bot, and they actually go through that process that I just described. So that's what we're working on now. But for now, like you can actually kind of use this to some degree without too much effort.

So you can use some code that will look like this. Okay. So you'd come here, you would initialize your knowledge base. You'd come down to here, right? So you'd use this sort of code here in order to add new papers to the database. Okay. If we come up to here, this is where we initialize that, right?

So we have the archive bot and we initialize it with this paper here. Okay. And the extractor is what you can see here. Okay. So with that, you can actually use this library. I'll add like a notebook or something that will show you how to do that. But this is still like not ready yet.

Okay. Because we want to basically make every interaction with this library accessible via the chat bot. But for now, you know, that's where we are. So I'll leave this video. I hope this has been a useful update. Hopefully there'll be a bit more progress on this very soon. And I'll be able to show you like an actual chat bot that you can genuinely use just like out of the box as a essentially like research assistant for archive papers and maybe in the future, other things as well.

But yeah, that's everything for now. So I hope this was interesting and useful. Thank you very much for watching and I will see you again in the next one. Bye. (soft music) (music fades) you