Code Monkey home page Code Monkey logo

langchain_rag's Introduction

langchain_rag

My first attempt to use LangChain for RAG.

To run, at command prompt: streamlit run ./app.py

To debug, press F5 in vs code. However the streamlit UI would run several threads and interfere with the debugger.

The backend LLMs are local or remote running either on LM Studio on Ollama. Using machine with GPU or NPU would help to reduce the response wait to below a minute. Otherwise, a pure CPU running local LLM would require waiting time of several minutes for a response.

The docs folder contains .md diary text entries generated by Bing chat of a fictious Singaporean male. The Python script uses Chroma DB to store and retrieve vectorized sentence embeddings. Before storing the vectors, the diary entries are split up into chunks then vectorized. You may add pdfs and htmls into the root or subfolders as you wished, the script will detect .md, .html and .pdf files.

The LamgChain QA retriever would convert the user query into vector embeddings and search in the Chroma DB for the closest related vectors to obtain the relevant chunks. These are mathematical calculation to find the closest related sentences to the query, by comparing the spatial distance between their vector representations.

These retrieved chunks are then used as context to send to LLM, along with the user query after merging into the prompt template. I have tested on the model: QuantFactory - Meta Llama 3 Instruct 7B Q5_K_M.guff model. This simple RAG is satisfactory for the simple document repository I tested on but the quality may suffer on complicated documents.

langchain_rag's People

Contributors

apollowing avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.