Llama Index and Supabase
!pip install -qU llama_index
import os
from llama_index import VectorStoreIndex, SimpleDirectoryReader
from llama_index.vector_stores import SupabaseVectorStore
os.environ['OPENAI_API_KEY'] = "[your_openai_api_key]"
documents = SimpleDirectoryReader('data').load_data()
index = VectorStoreIndex.from_documents(documents)
index.storage_context.persist()
DB_PASSWORD = os.environ['DB_PASSWORD']
DB_CONNECTION = f"postgresql://postgres:{DB_PASSWORD}@localhost:5431/db"
vector_store = SupabaseVectorStore(
postgres_connection_string=DB_CONNECTION,
collection_name='base_demo'
)
query_engine = index.as_query_engine()
response = query_engine.query("What did the author do growing up?")
print(response)
Top comments (0)