import psycopg2
from urllib.parse import quote_plus
from sqlalchemy import make_url
from llama_index.vector_stores.postgres import PGVectorStore
from llama_index.core import SimpleDirectoryReader, StorageContext
from llama_index.core import VectorStoreIndex


encoded_password = quote_plus(str)

db_name = "vector_db"
connection_string = f"dbname=vector_db user=database_user password={mypassword} host=localhost port=5432"

conn = psycopg2.connect(connection_string)
conn.autocommit = True

#with conn.cursor() as c:
    #c.execute(f"DROP DATABASE IF EXISTS {db_name}")
    #c.execute(f"CREATE DATABASE {db_name}")
    

#url = make_url(connection_string)
vector_store = PGVectorStore.from_params(
    database="mydatabase",
    host="localhost",
    password="mypassword",
    port=5434,
    user="postgres",
    table_name="bgrubindex",
    embed_dim=1536,  # openai embedding dimension
)

documents = SimpleDirectoryReader("./wpbgrubdata").load_data()

storage_context = StorageContext.from_defaults(vector_store=vector_store)
index = VectorStoreIndex.from_documents(
    documents, storage_context=storage_context, show_progress=True
)
