pgvector_real_wow.py
1 """PGVector Vector Store - Agent-First Example 2 3 Docker: docker run -d --name pgvector -e POSTGRES_PASSWORD=postgres -p 5433:5432 pgvector/pgvector:pg16 4 """ 5 import os 6 from praisonaiagents import Agent 7 8 url = os.getenv("PGVECTOR_URL", "postgresql://postgres:postgres@localhost:5433/postgres") 9 10 # Agent-first approach: use knowledge parameter with PGVector 11 agent = Agent( 12 name="Assistant", 13 instructions="You are a helpful assistant with access to documents.", 14 knowledge={"sources": ["./docs/guide.pdf"], "vector_store": {"provider": "pgvector", "url": url}} 15 ) 16 17 # Chat - agent uses knowledge for RAG 18 response = agent.chat("What information do you have?") 19 print(f"Response: {response}") 20 21 print("PASSED: PGVector with Agent") 22 23 # --- Advanced: Direct PGVector Usage --- 24 # import psycopg2 25 # conn = psycopg2.connect(url) 26 # cur = conn.cursor() 27 # cur.execute("CREATE EXTENSION IF NOT EXISTS vector")