Relyt
首先,您可能需要安装依赖项:
%pip install llama-index-vector-stores-relyt%pip install llama-index "pgvecto_rs[sdk]"然后按照官方文档启动relyt:
设置日志记录器。
import loggingimport osimport sys
logging.basicConfig(stream=sys.stdout, level=logging.INFO)logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))创建 pgvecto_rs 客户端
Section titled “Creating a pgvecto_rs client”from pgvecto_rs.sdk import PGVectoRs
URL = "postgresql+psycopg://{username}:{password}@{host}:{port}/{db_name}".format( port=os.getenv("RELYT_PORT", "5432"), host=os.getenv("RELYT_HOST", "localhost"), username=os.getenv("RELYT_USER", "postgres"), password=os.getenv("RELYT_PASS", "mysecretpassword"), db_name=os.getenv("RELYT_NAME", "postgres"),)
client = PGVectoRs( db_url=URL, collection_name="example", dimension=1536, # Using OpenAI’s text-embedding-ada-002)设置OpenAI
Section titled “Setup OpenAI”import os
os.environ["OPENAI_API_KEY"] = "sk-..."加载文档,构建 PGVectoRsStore 和 VectorStoreIndex
Section titled “Load documents, build the PGVectoRsStore and VectorStoreIndex”from IPython.display import Markdown, display
from llama_index.core import SimpleDirectoryReader, VectorStoreIndexfrom llama_index.vector_stores.relyt import RelytVectorStore下载数据
!mkdir -p 'data/paul_graham/'!wget 'https://raw.githubusercontent.com/run-llama/llama_index/main/docs/examples/data/paul_graham/paul_graham_essay.txt' -O 'data/paul_graham/paul_graham_essay.txt'# load documentsdocuments = SimpleDirectoryReader("./data/paul_graham").load_data()# initialize without metadata filterfrom llama_index.core import StorageContext
vector_store = RelytVectorStore(client=client)storage_context = StorageContext.from_defaults(vector_store=vector_store)index = VectorStoreIndex.from_documents( documents, storage_context=storage_context)# set Logging to DEBUG for more detailed outputsquery_engine = index.as_query_engine()response = query_engine.query("What did the author do growing up?")INFO:httpx:HTTP Request: POST https://api.openai.com/v1/embeddings "HTTP/1.1 200 OK"HTTP Request: POST https://api.openai.com/v1/embeddings "HTTP/1.1 200 OK"INFO:httpx:HTTP Request: POST https://api.openai.com/v1/chat/completions "HTTP/1.1 200 OK"HTTP Request: POST https://api.openai.com/v1/chat/completions "HTTP/1.1 200 OK"display(Markdown(f"<b>{response}</b>"))作者在成长过程中,既从事写作也进行编程。他们创作短篇小说,并尝试在IBM 1401计算机上编写程序。后来他们获得了一台微型计算机,开始更广泛地进行编程,编写了简单的游戏和一个文字处理器。