PolarisRAG: Fast and Easy Retrieval-Augmented Generation
Project description
🚀 PolarisRAG: Fast and Easy Retrieval-Augmented Generation
Install
- Install from source (Recommend)
cd PolarisRAG
pip install -e .
- Install from PyPI
pip install polarisrag
Quick Start
- All the code can be found in the
examples - Set ZhipuAI API key in environment if using ZhipuAI models:
export ZHIPUAI_API_KEY="537...". - Download the demo text "A Christmas Carol by Charles Dickens":
curl https://raw.githubusercontent.com/gusye1234/nano-graphrag/main/tests/mock_data.txt > ./book.txt
- Maybe you can try loading environment variables like this. Create a new
.envfile
ZHIPUAI_API_KEY="537..."
OPENAI_API_KEY="sk-..."
OPENAI_BASE_URL="https://api..."
QWEN2_API_KEY="sk-no-key-required"
QWEN2_BASE_URL="http://127.0.0.1:8080/v1"
from dotenv import load_dotenv, find_dotenv
load_dotenv(find_dotenv(), override=True)
Use the below Python snippet (in a script) to initialize PolarisRAG and perform queries:
import os
os.environ["ZHIPUAI_API_KEY"] = ""
from polarisrag import PolarisRAG
# 定义工作空间
WORKING_DIR = "documents"
rag = PolarisRAG(working_dir=WORKING_DIR)
# 初始化rag,加载embedding、vector、llm
rag.init_rag()
# 插入数据
with open("documents/test.txt", 'r') as f:
rag.insert(f.read())
print(rag.chat("什么是BERT"))
print(rag.chat("如何下载BERT-base-chinese预训练模型"))
Use PolarisRAG through a dictionary configuration
from polarisrag import PolarisRAG
WORKING_DIR = "documents"
embedding_conf = {
"class_name": "HFEmbedding",
"class_param": {
"pretrain_dir": '/root/.cache/modelscope/hub/BAAI/bge-large-zh-v1___5'
}
}
vector_conf = {
"class_name": "MilvusDB",
"class_param": {}
}
llm_model_conf = {
"class_name": "ZhipuLLM",
"class_param": {
"model": "glm-4-flash",
"is_memory": "True"
}
}
rag = PolarisRAG(working_dir=WORKING_DIR,
embedding_model=embedding_conf,
vector_storage=vector_conf,
llm_model=llm_model_conf)
rag.init_rag()
with open("documents/test.txt", 'r') as f:
rag.insert(f.read())
result = rag.chat("什么是BERT")
print(result)
result = rag.chat("如何下载BERT-base-chinese预训练模型")
print(result)
Introduce components for use
import os
from polarisrag import PolarisRAG
from polarisrag.embedding import ZhipuEmbedding
from polarisrag.vector_database import MilvusDB
from polarisrag.llm import ZhipuLLM
from polarisrag.utils import FolderLoader
# api_key
ZHIPUAI_API_KEY = ""
# 工作空间
WORKING_DIR = "documents"
embedding_model = ZhipuEmbedding(api_key=ZHIPUAI_API_KEY)
llm_model = ZhipuLLM(api_key=os.getenv("ZHIPUAI_API_KEY"))
loader = FolderLoader(folder_path=WORKING_DIR)
docs = loader.get_all_chunk_content()
vector_db = MilvusDB({"embedding_model": embedding_model})
# 创建集合
vector_db.create_collection("default")
vector_db.insert(docs=docs)
rag = PolarisRAG(
working_dir=WORKING_DIR,
embedding_model=embedding_model,
vector_storage=vector_db,
llm_model=llm_model,
is_memory=True
)
print(
rag.chat("什么是BERT")
)
🌟Citation
@article{guo2024polarisrag,
title={PolarisRAG: Fast and Easy Retrieval-Augmented Generation},
author={Runke Zhong},
year={2024}
}
保持热爱,奔赴星海!
这个世界上唯有两样东西能让我们的心灵感到深深的震撼:一是我们头上灿烂的星空,一是我们内心崇高的道德法则
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file polarisrag-0.0.1.tar.gz.
File metadata
- Download URL: polarisrag-0.0.1.tar.gz
- Upload date:
- Size: 14.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.5 CPython/3.10.14 Linux/5.15.167.4-microsoft-standard-WSL2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4f671bd03744265d286646b133144c22bfb59f7b3bb7e674ee0ff08d7dcfc4e3
|
|
| MD5 |
50675e4c5e65099c4443e41bb7aab366
|
|
| BLAKE2b-256 |
807b68e0b4abd70abd435b8aafec04ff2d8fae0c683d672dcf7a5eca74575070
|
File details
Details for the file polarisrag-0.0.1-py3-none-any.whl.
File metadata
- Download URL: polarisrag-0.0.1-py3-none-any.whl
- Upload date:
- Size: 17.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.5 CPython/3.10.14 Linux/5.15.167.4-microsoft-standard-WSL2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bd7304c4328ae6b6b2e29d47535de3d465c007c38fe0c36fb8e3e3233c47bf71
|
|
| MD5 |
6d7fd831a2113949ec6d26d21ac41789
|
|
| BLAKE2b-256 |
ed7227cf9a3648a89060cf8a67de9b9c16545dbe8002b510b831edc1efa3e469
|