We built a simple RAG (Retrieval-augmented generation) pipeline from scratch, using the following open sources models on huggingface:
- Embedding: FlagEmbedding
- LLM: Qwen2.5
Two ways:
- rag_simple.py: simple vector store in memory.
- rag_chroma.py: vector store with Chroma Vector DB
RAG modules:
- SimpeFileReader: just read a text file
- SentenceSplitter: split the docs with specified chunk size and overlap.
- VectorStoreIndex: build a vector store with the chunked nodes and create the index.
Work steps:
- read the text file.
- normalize the file content.
- split the content into chunks.
- build the vector store with the chunks.
- define the question.
- query the context of this question from vector store.
- format the prompt with the question and it's context.
- predict the prompt with the LLM.
- get the answer.
Tested and run under Python 3.12.6, the following packages are also required
The test text documents were obtained from Google search on the Internet.