This repository contains the example of the simple QnA system based on the
LLM and LangChain. As the vector search engine I have used Qdrant.
Note
This project is based on Python 3.10 and uses poetry to manage dependencies.
- Clone the repository using
git clonecommand. - Open the terminal and go to the project directory using
cdcommand. - Create virtual environment using
python -m venv venvorconda create -n venv python=3.10command. - Activate virtual environment using
source venv/bin/activateorconda activate venvcommand. - Install poetry using instructions from
here. Use
with the official installersection. - Set the following option to disable new virtualenv creation:
poetry config virtualenvs.create false - Install dependencies using
poetry install --no-rootcommand. The--no-rootflag is needed to avoid installing the package itself. - Setup
pre-commithooks usingpre-commit installcommand. More information aboutpre-commityou can find here. - Run the test to check the correctness of the project work using following
command:
python -m unittest -b
- After successful passing of the tests, you can work with the project!
- If you want to add new dependencies, use
poetry add <package_name>command. More information aboutpoetryyou can find here. - If you want to add new tests, use
unittestlibrary. More information aboutunittestyou can find here. All tests should be placed in thetestsdirectory. - All commits should be checked by
pre-commithooks. If you want to skip this check, usegit commit --no-verifycommand. But it is not recommended to do this. - Also, you can run
pre-commithooks manually usingpre-commit run --all-filescommand. - More useful commands you can find in
Makefile.
Warning
You should have wget to files and docker to run Qdrant and Redis services.
Important
Knowledge base for RAG consists of two parts: pdf files and data from the wikipedia.
First part will be downloaded manually by the script and second part will be downloaded
from the code.
- Run
make download_datasetcommand to download thepdf files. Those files will be placed in thedatadirectory and it only a one part of the full dataset that will be used. - Run
make run_qdrantcommand to start theQdrantservice. It will be available onhttp://localhost:6333address. - Run
make run_rediscommand to start theRedisservice. It will be necessary to cache theLLMprompts and requests instep 5. - Run the notebook
notebooks/01-open-source-llms-langchain.ipynbto download the full dataset, index it and run theQnAexample with localLLMs. This notebook show only simple example of theQnAsystem. - Run the notebook
notebooks/02-open-ai-langchain-base.ipynbto download the full dataset, index it and run theQnAexample withOpenAI LLMs. This example is more complex and show how to evaluate theQnAsystem. - I can run
REST APIforQnAsystem usingmake run_apicommand.Swaggerwill be available onhttp://localhost:8000/docsaddress.
- Mastering RAG: How To Architect An Enterprise RAG System -
this article describes how to build the
RAGsystem for enterprise and7 Failure PointsofRAGsystems. - Using langchain for Question Answering on Own Data -
good introduction into the
LangChainandQnAsystems. Contains a lot of useful diagrams. - RAG: How to Talk to Your Data -
yet another good introduction into the
RAGsystems with useful examples. - HOW-TO: Build a ChatPDF App over millions of documents with LangChain and MyScale in 30 Minutes -
just a quick example of how to build a
QnAsystem usingLangChain. - How LangChain Implements Self Querying -
into the details of how
LangChainimplementsself-querying. - SPLADE: sparse neural search -
SPLADEis a sparse neural network for efficient vector search. - Weaviate Hybrid Search -
just a quick example hybrid search using
LangChainandWeaviate. - Qdrant Hybrid Search -
just a quick example hybrid search using
LlamaIndexandQdrant. - Building an Ecommerce-Based Search Application Using Langchain and Qdrant’s Latest Pure Vector-Based Hybrid Search -
yet another example of the
LangChainandQdranthybrid search usingSPLADE. - Azure OpenAI demos - Azure OpenAI demos repository.
- A complete Guide to LlamaIndex in 2024 -
LlamaIndexblog post. - Building LLM-based Application Using Langchain and OpenAI -
good text explanation of the
LangChainandOpenAIintegration. - LOTR (Merger Retriever) in LangChain -
Merger Retrieveris aLangChainretriever that merges results from multiple retrievers. - What is the difference between LOTR(Merger Retriever) and Ensemble Retriever -
LOTRvsEnsemble Retrieverissue. - TruLens -
TruLensis an open-source package that provides instrumentation and evaluation tools forLLMbased applications. - Better RAG with Merger Retriever (LOTR) and Re-ranking Retriever (Long Context Reorder)
- Long-Context Reorder -
LongContextReorderis a retriever that re-ranks the results of another retriever. - Lost in the Middle: How Language Models Use Long Contexts -
LLMsandlong contextsarticle. - MultiVector Retriever -
MultiVectorRetrieveris a retriever that uses multiple vector stores to retrieve results. - Harnessing Retrieval Augmented Generation With Langchain -
RAGwithLangChainarticle. Contains example with good and simple chat application. - LangChain Interface methods -
LangChaininterface methods. How to stream the output, how to asynchronously run the query, etc. - Save time and money by caching OpenAI (and other LLM) API calls with Langchain -
LLMcaching inLangChain. - LLM Caching integrations -
LLMcaching inLangChain. - LLM Caching -
LLMcaching inLangChain. - Multi-Vector Retriever for RAG on tables, text, and images -
Multi-Vector RetrieverforRAGon tables, text, and images. - LangChain Spark AI -
LangChainandSparkintegration. - Large Language Model for Table Processing: A Survey -
LLMfor table processing survey. - Sparse Vectors in Qdrant: Pure Vector-based Hybrid Search - how to add
sparse vectorsinQdrant - Hybrid Search: SPLADE (Sparse Encoder) - more about
SPLADE - Self-reflective RAG with LangGraph: Self-RAG and CRAG -
Self-RAGandCRAGwithLangGraph. - Webinar "A Whirlwind Tour of ML Model Serving Strategies (Including LLMs)"
- Prompt-Engineering for Open-Source LLMs
- Mitigating LLM Hallucinations with a Metrics-First Evaluation Framework
- Efficient Fine-Tuning for Llama-v2-7b on a Single GPU
- DeepLearning AI courses - that's a good courses to start with
- Text book - articles on AI fundamentals/concepts
- LLM Course - course with roadmaps and Colab notebooks.
- Building LLM-Powered Apps -
W&B course about
LLMs. - Training and Fine-tuning Large Language Models (LLMs) -
W&B course about
LLMs. - Large Language Models (LLMs): Foundation Models from the Ground Up -
Databricks course about
LLMs. - Large Language Models (LLMs): Application through Production -
Databricks course about
LLMs. - Як створити спеціалізований чатбот. Детальний гайд на основі кейса клієнта -
article about
chatbotsinUkrainian.