Reputation: 21
from llama_index.indices.vector_store import VectorStoreIndex
from llama_index.vector_stores import PGVectorStore
import textwrap
import openai
import os
import sys
sys.getdefaultencoding()
os.environ["OPENAI_API_KEY"] = "KEY"
openai.api_key = "KEY"
## Load documents
documents = SimpleDirectoryReader("./data/paul_graham").load_data()
print("Document ID:", documents[0].doc_id)
## Create the database
import psycopg2
connection_string = "postgresql://postgres:123456@localhost:5432"
db_name = "vector_db"
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}")
## Create the index
from sqlalchemy import make_url
url = make_url(connection_string)
vector_store = PGVectorStore.from_params(
database=db_name,
host=url.host,
password=url.password,
port=url.port,
user=url.username,
table_name="paul_graham_essay",
embed_dim=1536, # openai embedding dimension
)
storage_context = StorageContext.from_defaults(vector_store=vector_store)
index = VectorStoreIndex.from_documents(
documents, storage_context=storage_context, show_progress=True
)
query_engine = index.as_query_engine()
I am having this error when running the code above, I would like to know how to install this vector extention, thanks.
psycopg2.errors.FeatureNotSupported: ERROR: Extension 'vector' is not available DETAIL: Could not open extension control file "C:/Program Files/PostgreSQL/16/share/extension/vector.control": No such file or directory. HINT: Extensions must first be installed on the system where PostgreSQL is running.
When I am compiling pgvector files make install, I am facing this error
"process_begin: CreateProcess(NULL, uname -s, ...) failed. Makefile:16: pipe: No error process_begin: CreateProcess(NULL, uname -m, ...) failed. Makefile:24: pipe: No error Makefile:48: C:/PostgreSQL/16/lib/pgxs/src/makefiles/pgxs.mk: No such file or directory make: *** No rule to make target 'C:/PostgreSQL/16/lib/pgxs/src/makefiles/pgxs.mk'. Stop."
Upvotes: 0
Views: 4267
Reputation: 21
Solved:
To solve this issue, I followed the installations method for windows https://github.com/pgvector/pgvector#windows.
Note: I run the command line a adminstrator.
Upvotes: 0