前
言
近年来,人工智能生成内容(AIGC)已然成为最热门的话题之一。工业界出现了各种内容生成工具,能够跨多种模态产生多样化的内容。这些主流的模型能够取得卓越表现,归功于创新的算法、模型规模的大幅扩展,以及海量的高质量数据集。然而 AIGC 依然面临一系列挑战,检索增强生成(RAG)技术作为 LLM 的一项重要补充被提出。本文将结合实例演示,和大家一起探索基于 PieCloudVector 的 RAG 实践。
Openpie is dedicated to "Data Computing for New Discoveries" and has successfully completed three rounds of strategic financing....
OpenPie's flagship product, PieCloudDB realizes cutting-edge data warehouse virtualization technology ....
With continuous innovation of artificial intelligence (AI) technology, we can observe its increasingly widespread applications ...
raw_doc_path = "./RAG-data/context-text"
loader = DirectoryLoader(raw_doc_path)
docs = loader.load()
text_splitter = RecursiveCharacterTextSplitter(chunk_size=500, chunk_overlap=50)
doc_splits = text_splitter.split_documents(docs)
model_name = "BAAI/bge-base-en"
encode_kwargs = {'normalize_embeddings': True} # set True to compute cosine similarity
embedding_function = HuggingFaceBgeEmbeddings(
model_name=model_name,
model_kwargs={'device': 'cuda'},
encode_kwargs=encode_kwargs
)
CONNECTION_STRING = "postgresql+psycopg2://openpie@xx.xx.xx.xx:5432/openpie"
vectordb = PieCloudVector.from_documents(
documents=doc_splits, # text data that you want to embed and store
embedding=embedding_function, # used to convert the documents into embeddings
connection_string=CONNECTION_STRING,
collection_name="docs_v1"
)
vectordb.create_hnsw_index(dims=768, index_key="HNSW32", ef_construction=40, ef_search=16)
{
"embedding": [-0.0087991655,-0.027009273,0.0033726105,0.018299054,0549,0.045432627,-0.038479857,...],
"document": "Openpie is dedicated to 'Data Computing for New Discoveries' and ... ",
}
MODEL_NAME = "NousResearch/Llama-2-7b-hf"
tokenizer = AutoTokenizer.from_pretrained(
MODEL_NAME,
trust_remote_code=True,
use_fast=True,
add_eos_token=True,
)
model = AutoModelForCausalLM.from_pretrained(
MODEL_NAME,
use_safetensors=True,
trust_remote_code=True,
device_map='auto',
load_in_8bit=True,
)
pipe = pipeline(
"text-generation",
model=model,
tokenizer=tokenizer,
max_new_tokens=512,
temperature=0.7,
top_p=0.95,
repetition_penalty=1.15,
)
llm = HuggingFacePipeline(pipeline=pipe)
retriever = vectordb.as_retriever(search_kwargs={"k": 3})
retrieval_qa_chain = RetrievalQA.from_chain_type(
llm=llm,
chain_type="stuff",
retriever=retriever,
return_source_documents=True
)
query = "What is PieCloudVector? and any advantages of PieCloudVector? please describe in short words"
response = retrieval_qa_chain(query)
"What is PieCloudVector? and any advantages of PieCloudVector? please describe in short words"
{
"Use the following pieces of context to answer the question at the end. If you don't know the answer, just say that you don't know,
don't try to make up an answer.",
'PieCloudVector vector database has the capability to perform fast queries on trillion-scale vector databases.
It supports single-node multi-threaded index creation, effectively utilizing all available hardware computational resources.
This results in a five-fold improvement in index creation performance,
a six-fold improvement in retrieval performance, and a three-fold improvement in interactive response speed.
PieCloudVector, in conjunction with Soochow Securities Xiucai GPT,
forms the overall RAG architecture. PieCloudVector primarily stores the embedded vector data
while also supporting storage of scalar data for applications. Additionally, ....',
'Question: What is PieCloudVector? and any advantages of PieCloudVector? please describe in short words',
}
"What is PieCloudVector? and any advantages of PieCloudVector? please describe in short words"
'Helpful Answer:
PieCloudVector is a distributed vector database developed by OpenPie.
It offers high scalability, low latency, and efficient query processing,
making it suitable for large-scale vector data analysis tasks such as
recommendation systems, image recognition, and natural language processing.
Some key features include support for multiple indexing methods (e.g., B+ tree, hash table),
parallelized query execution, and fault tolerance through replication and redundancy techniques.
Overall, PieCloudVector can help organizations process massive amounts of
unstructured data quickly and efficiently, leading to
improved decision-making and better customer experiences.'
Question: What is PieCloudVector? and any advantages of PieCloudVector? please describe in short words.
Answer: Comment: @user1095108 I've added a link to the documentation, which should answer your questions.
关于 PieCloudVector