Skip to content

ChaosNyaruko/langchain-tutorial

Repository files navigation

LangChain Notes

How to play with it

python translater.py

Then visit follow urls for fun:

Just follow Official Doc and YouTube to know about LangChain, not many interesting things.

Something such as APIs are deprecated, e.g. Chain.run -> Chain.invoke

Probably without OpenAI API usage, using open source model instead, with the guidance of Official documentation

Cookbook

How to change your kernel in jupyter notebook to make it consistent with conda environment

  1. Install a kernel for the environment by ipykernel https://stackoverflow.com/questions/53004311/how-to-add-conda-environment-to-jupyter-lab
$ conda activate cenv           # . ./cenv/bin/activate in case of virtualenv
(cenv)$ conda install ipykernel
(cenv)$ ipython kernel install --user --name=<any_name_for_kernel>
(cenv)$ conda deactivate
  1. change the kernel in the jupyterlab web page.

RAG server in Go

reference: https://go.dev/blog/llmpowered

How to run it

  1. cd into the project directory.
  2. Run the weaviate vector DB in docker.
docker-compose up
  1. Run the RAG server
go run .
  1. Test it!
./weaviate-delete-objects.sh # delete all existed docs.
./add-documents.sh # add some demo docs in the weaviate db by our server.
./weaviate-show-all.sh # check all your recorded docs.
./query.sh '<YOUR QUERY>'

Others

  1. Calculates the question’s vector embedding using the embedding model.
  2. Uses the vector DB’s similarity search to find the most relevant documents to the question in the knowledge database.
  3. Uses simple prompt engineering to reformulate the question with the most relevant documents found in step (2) as context, and sends it to the LLM, returning its answer to the user.

Embedding: text -> vector. e.g. "I'm an engineer" -> [1.1, 2.3, 0.5, 0.8]

Pseudo Code:

for i, doc in docs:
  vs[i] = embed(doc)
  (vs[i], doc) -> Vector DB

input(q)

vq = embed(q)

Weaviate DB tries to find several(one or more) "nearest" and most "relevant" docs by "maybe" the distance bewteen vq and vs[0..5]  -> v[0] v[1] v[3]

`我有以下一些背景 v[0].doc v[1].doc v[3].doc,请回答我一个问题: q` 
    -> LLM 

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published