mirror of
https://github.com/supabase/supabase.git
synced 2026-10-17 23:29:08 +03:00
6.1 KiB
6.1 KiB
In [1]:
!pip install -qU vecs datasets llama_index html2textIn [ ]:
import logging
import sys
# Uncomment to see debug logs
# logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
# logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))
from llama_index.core.storage import StorageContext
from llama_index.readers.web import SimpleWebPageReader
from llama_index.indices.vector_store import VectorStoreIndex
from llama_index.vector_stores.supabase import SupabaseVectorStore
import textwrap
import html2textIn [ ]:
import os
os.environ['OPENAI_API_KEY'] = "[your_openai_api_key]"In [ ]:
essays = [
'paul_graham_essay.txt'
]
documents = SimpleWebPageReader().load_data([f'https://raw.githubusercontent.com/supabase/supabase/master/examples/ai/llamaindex/data/{essay}' for essay in essays])
print('Document ID:', documents[0].doc_id, 'Document Hash:', documents[0].hash)In [5]:
# Substitute your connection string here
DB_CONNECTION = "postgresql://postgres:password@localhost:5431/db"
vector_store = SupabaseVectorStore(
postgres_connection_string=DB_CONNECTION,
collection_name='base_demo'
)
storage_context = StorageContext.from_defaults(vector_store=vector_store)
index = VectorStoreIndex.from_documents(documents, storage_context=storage_context)In [7]:
query_engine = index.as_query_engine()
# Ask a question
response = query_engine.query("What did the author do growing up?")
# Print the response
print(response)