
In this video, I show a couple example of how you can get easily set up with some high level examples using the Llamaindex Typescript/Javascript SDK. I will show you how you can easily query either a single document or a directory of documents with LlamaIndex. Don't forget to npm/pnpm/yarn/bun i llamaindex! https://www.llamaindex.ai/ https://www.npmjs.com/package/llamaindex https://ts.llamaindex.ai/ Connect and Support I'm the developer behind Developers Digest. If you find my work helpful or enjoy what I do, consider supporting me. Here are a few ways you can do that: Patreon: Support me on Patreon at patreon.com/DevelopersDigest Buy Me A Coffee: You can buy me a coffee at buymeacoffee.com/developersdigest Website: Check out my website at developersdigest.tech Github: Follow me on GitHub at github.com/developersdigest Twitter: Follow me on Twitter at twitter.com/dev__digest
--- type: transcript date: 2023-12-13 youtube_id: i1qTOKpTUWo --- # Transcript: Get Started With Llamaindex.TS In 8 Minutes in this video I'm going to be showing you Lama index which is a simple and flexible data framework that connects custom data sources to large language models so what this allows you to do is it allows you to access and interpret private data on large scales without having to retrain the underlying model with that newer set of data so essentially what llama index does is it ingests the data from various sources whether it's apis databases uh PDFs um through what are known as data connectors and through those data connectors it indexes those documents and embeds them which we'll get into in just a moment and by creating what's known as a rag system or a retrieval augmented generation system it combines the llms with that private knowledge base which allows you to query those documents or apis or databases or the combination of all of them so it's a very powerful tool and it allows you to make applications such as QA systems chatbots uh agents those types of things so I'm going to show you their typescript implementation and I'm going to run through two examples to get you started so I just wanted to touch on this so it's very similar to Lang chain I just wanted to show another example of one of these Frameworks on my channel where I think they're doing really excellent work so where Lama index really caught my eye is on their social media feeds they have really good content around rag systems and some of the new approaches these Cutting Edge approaches on how to actually query and embed documents what works well what doesn't and the ranking of all of these different types of things so definitely a really good option to check out on their social media if you're interested so what you can do I'm going to put all these links in the description of the video but essentially there is a GitHub repository for both their python implementation as well as their typescript implementation you can go ahead check these out there's also a couple examples on here uh to get you started but there is also a typescript documentation page where you can go ahead and look through what's all available right within their website as well so in a lot of the examples including the examples I'm going to be showing you here you will need an openai API key so if you don't already have one just head over to open.com uh platform API keys I believe is or just Google API Keys open AI get an API key and then what we're going to be doing is we're going to just init a a simple project here uh in our uh folder in our vs code and we're going to create a EnV to start so within your EnV just write out open aore aior key and paste in that key just like you see there so within the two examples we're going to be running through one example where we query and are able to ask questions from one document and then in this second example I'm going to show you how you can also do this with a directory of documents so first to get started just import FS to be able to use our file system with a node then next we're going to import two things from the Llama index Library we're going to D structure a document as well as Vector store index which I'll touch on both of those in just a moment next we're going to import EnV and configure it to be able to reference our opening I API key then from there we're just going to wrap everything within an asynchronous function so all of these things will occur asynchronously so we have to make sure that everything is happening one after another so the first thing that we're going to do is we're going to read a simple file so I just have the state of a union uh address where it's a relatively long document that we'll be able to ask questions of so from there we're just going to create a new document instance and this is going to be what we use to create our Vector uh or our Vector store index rather so the vector store index essentially what this portion does is it's taking that document or series of documents and it's breaking it up into uh smaller little chunks and from those little chunks it's quering the opening eye embedding Z point and essentially what's being returned is this array of different numbers and those numbers are a representation of the similarity uh between each other so you can think of say an example of say something like zoo animals those will be closer together than say A you query like a zoo animal and like something arbitrary like a car or types of cars or something so it's essentially mapping the relatedness and the similarity between words or tokens so next what we're going to be doing is we're going to convert that Vector store index into a query engine and this is going to be how we actually ask the question of the document so we're going to just simply ask what were the highlights within the document and then we're going to log out that response so if I save save out the file here and I just run node one for our first example we can see here that we don't have the example text being referenced properly so I'm just going to go ahead put that here run it one more time so essentially what it's doing each time that you run this you are going to be embedding everything within the that particular text file so it's combing through it's getting the top results from that document and here it essentially is giving us somewhat of a summary of the highlevel overview of what was discussed within that document So within the next document it's very similar we're going to import FS we're going to import document Vector store index and this time also simple directory reader so it just goes to show how simple of an implementation that this is or is to use I should say uh because being able just to point a uh folder with within your application that you want to have read and embedded and all of that it makes setting these things up really simple right so again we're going to import MV just like we did we're going to set up our asynchronous function and then here we're just going to point to the directory that we want red so in our directory we have two files and the two files that I put in here are actually just the files that I'm using for the example so I'm going to be using these and asking question or's just a simple question in the demonstration here so we're going to be setting up our directory reader then similar to the document reader we're going to have our directory reader and load all of the files within the directory path so again we're going to break up all of the documents into chunks we're going to embed them and create a vector store for them then from there just like in the first example we're going to create another query index and this time what we're going to be doing is we're going to iterate through all of them and I'm just going to ask the question of each document explain this code to me as if I was 5 years old and then we're going to run that function so if I just go ahead and say node two and run that what it's doing here is these files like I said are the exact two files here explaining what I just explained here so if we look at the results here you can see the first result came in and then the second result came in and it's just going through and iterate or not iterating but it's just going through and explaining um the documents uh answering that question for each of them so say if you had a 100 different files here in this particular example it would Loop through these and give you them one by one as it came up with results so that's pretty much it this is just a basic example on how you can get started with something like llama index but hopefully you found this video useful if you did please like comment share and subscribe and otherwise until the next one
Weekly deep dives on AI agents, coding tools, and building with LLMs - delivered to your inbox.
Free forever. No spam.
Subscribe FreeNew tutorials, open-source projects, and deep dives on coding agents - delivered weekly.
Technical content at the intersection of AI and development. Building with AI agents, Claude Code, and modern dev tools - then showing you exactly how it works.