2 ms·
https://github.com/lamini-ai/lamini-sdk/tree/main/03_RAG https://github.com/lamini-ai/lamini-sdk/tree/main/03_RAG You can implement RAG in 80 lines of python a
by gdiamos 3y ago
https://github.com/lamini-ai/lamini-sdk/tree/main/03_RAG https://github.com/lamini-ai/lamini-sdk/tree/main/03_RAG
You can implement RAG in 80 lines of python and 0 SaaS libraries.
It's extremely easy.
1. Load your data as a giant string (streaming)
2. Chunk it (big chunk size, small chunk steps)
3. Call an LLM to convert chunk -> embedding, store in an index (or just concat it onto a numpy array)
4. Call an LLM to convert query -> embedding
5. Compute cosine similarity between the embeddings, pick the max
6. Insert the picked chunks into the LLM prompt
That's it. I'd encourage you to try to implement it yourself.
Anything beyond this is unnecessary complexity.
I walk through the code/whiteboard of the whole thing in this video: https://www.youtube.com/watch?v=Xkzd_YNbWmc&t=6003s https://www.youtube.com/watch?v=Xkzd_YNbWmc&t=6003s