DEV Community

ASHDEEP SINGH
ASHDEEP SINGH

Posted on

Building our own RAG

This week in Learning of AI was spent in learning how RAGs work.
Now think of RAG as a "FACE" to which you can talk , given that the brain of this "FACE" is "DATA" , which you provide it.
Thus you can know what a document / pdf / website contains just by chatting with the "FACE".

Technically , the process of setting up such a thing is easier than you might think.

Follow the github for code

Follow the below blueprint of setting up a RAG based chatBOT.

Select Sources: PDFs or websites. Choose which data and from where you wish to inject data into the model. Refer files named indexing.js (for pdf loading) and webindex.js (for website loading).

Once done , the next procedure is same for both pdf loading and webloading (you can also do both in same project).

Chunking: Divie the text into chunks. It is these chunks that will be stored in the Database as vector embeddings.

Metadata: source, title, section, date, tags are to be added , but you dont have to do it , as your vectorDB will do it for each chunk you give it.

Embeddings: Make vector embeddings for each chunk (again done by code but you need to call the code command)

Index/Store: Store the result uptill this point in the VectorDB.

Now comes the fun part.

For each User message , make a query embedding out of it.

Retrieve: Get similar chunks from VectorDB and then use them to generate the response for the user. You just need to inject this chunk into the model and you're good to go for processing the user query.

And that's it folks. See how easy it was for setting up a RAG. Now there's more to the story , like fine-tuning the RAG, it's system design. But we'll cover that some other day.

Keep following for more.

Peace.......

Top comments (0)