使用 llamafile 的最小本地 RAG 一个非常基础的交互式 CLI,用于使用 llamafile 进行嵌入和文本索引以及查询文档…
使用 llamafile 的最小本地 RAG 一个非常基础的交互式 CLI,用于使用 llamafile 进行嵌入和文本索引以及查询文档…
A very basic interactive CLI for indexing and querying documents using llamafiles for embeddings and text generation. Index is based on a FAISS vector store. Default embedding model is mxbai-embed-large-v1 (llamafile link) and text generation model is mistral-7b-instruct-v0.2 (llamafile link). (These can be changed by editing setup.sh.)
Setup:
cp .env.example .env
./setup.shThis script will download llamafiles from HuggingFace and may take several minutes depending on your internet connection.
NOTE: setup script requires pyenv
To start the app, run:
./app.shWhen you run the app, it will:
toy_data/ directory into a vector store (the "index"). Contents of the toy_data/ directory:1.txt: Alice likes red squares.
2.txt: Bob likes blue circles.
3.txt: Chris likes blue triangles.
4.txt: David does not like green triangles.
5.txt: Mary does not like circles.Enter query (ctrl-d to quit): [What does Alice like?]>If you just hit Enter here, by default the query will be "What does Alice like?". The app output should look like:
=== Query ===
What does Alice like?
=== Search Results ===
0.7104 - " alice likes red squares ."
0.5229 - " bob likes blue circles ."
0.4088 - " chris likes blue triangles ."
=== Prompt ===
"You are an expert Q&A system. Answer the user's query using the provided context information.
Context information:
alice likes red squares .
bob likes blue circles .
chris likes blue triangles .
Query: What does Alice like?"
(prompt_ntokens: 55)
=== Answer ===
"
Answer: Alice likes red squares."
--------------------------------------------------------------------------------Here some other queries you could try:
That's pretty much it.
You can change most app settings via the .env file. The default file should look like:
EMBEDDING_MODEL_PORT=8080
GENERATION_MODEL_PORT=8081
INDEX_LOCAL_DATA_DIRS=local_data,toy_data
INDEX_TEXT_CHUNK_LEN=128
INDEX_SAVE_DIR=./index-toySee settings.py for all available options.
By default, the app uses:
By default, the app is configured to index the contents of the directories listed in INDEX_LOCAL_DATA_DIRS, which are local_data and toy_data. Currently we only support indexing .txt files.
First, in your .env, change INDEX_SAVE_DIR to wherever you want your index to be saved. The app will not change or overwrite an existing index, so either change the directory in the .env or delete the existing index at ./index-toy.
There are 2 ways to add data:
.txt files to the local_data/ directory. You can remove toy_data/ from the INDEX_LOCAL_DATA_DIRS list in our .env file. You can also just add another directory to the INDEX_LOCAL_DATA_DIRS list.INDEX_URLS var in your .env file, e.g. INDEX_URLS=url1,url2,....暂无开放 Issues,或尚未同步最近议题。