Skip to main content

🚀 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 .env file
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}
}

保持热爱,奔赴星海!

这个世界上唯有两样东西能让我们的心灵感到深深的震撼:一是我们头上灿烂的星空,一是我们内心崇高的道德法则

Metadata

Release files for polarisrag 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for polarisrag 0.0.1
File Size Uploaded
polarisrag-0.0.1.tar.gz 14.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for polarisrag 0.0.1
File Interpreter ABI Platform
polarisrag-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 31.6 kB

Release files / polarisrag-0.0.1.tar.gz

Download URL polarisrag-0.0.1.tar.gz
Size 14.3 kB
Tags Source
SHA-256 checksum
How to use checksums
4f671bd03744265d286646b133144c22bfb59f7b3bb7e674ee0ff08d7dcfc4e3
BLAKE2b-256 checksum
How to use checksums
807b68e0b4abd70abd435b8aafec04ff2d8fae0c683d672dcf7a5eca74575070
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.5 CPython/3.10.14 Linux/5.15.167.4-microsoft-standard-WSL2

Release files / polarisrag-0.0.1-py3-none-any.whl

Download URL polarisrag-0.0.1-py3-none-any.whl
Size 17.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bd7304c4328ae6b6b2e29d47535de3d465c007c38fe0c36fb8e3e3233c47bf71
BLAKE2b-256 checksum
How to use checksums
ed7227cf9a3648a89060cf8a67de9b9c16545dbe8002b510b831edc1efa3e469
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.5 CPython/3.10.14 Linux/5.15.167.4-microsoft-standard-WSL2

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page