how do you specify column names for pgvector ? It keeps lookin for name column
import os
from dotenv import load_dotenv
import logging
from agno.agent import Agent, AgentKnowledge
from agno.models.openai import OpenAIChat
from agno.vectordb.pgvector import PgVector, SearchType
from agno.embedder.openai import OpenAIEmbedder
from agno.tools.sql import SQLTools # Import SQL Tools
from pydantic import BaseModel
from typing import List, Any
# Load environment variables from .env file
load_dotenv()
# Setup logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
# Define the database URL using the value from the .env file.
db_url = os.getenv("DATABASE_URL")
# Fetch OpenAI API key from environment variables.
openai_api_key = os.getenv("OPENAI_API_KEY")
# Initialize PgVector instance for the 'articles' table.
vector_db = PgVector(
db_url=db_url,
table_name="articles", # This is the table that holds your articles.
schema="public", # Specify the correct schema (public) so the query uses public.articles.
embedder=OpenAIEmbedder(api_key=openai_api_key), # Using the OpenAI embedder with API key from .env.
search_type=SearchType.hybrid, # Hybrid search mixes vector and keyword matching.
)
class ArticleSearchResult(BaseModel):
articles: List[dict] = [] # Provide a default value so 'articles' is not treated as required
## Wrap PgVector with AgentKnowledge for proper search handling.
knowledge_base = AgentKnowledge(vector_db=vector_db)
# Instantiate SQL tool for retrieving table schema information.
sql_tool = SQLTools(db_url=db_url, schema="public", describe_table=True)
# Create the Agno agent with the integrated knowledge base.
agent = Agent(
model=OpenAIChat(id="gpt-4o", structured_outputs=False), # Disable structured outputs.
knowledge=knowledge_base, # Use AgentKnowledge for proper handling of search parameters.
search_knowledge=True, # Enable the search tool for the knowledge base.
tools=[sql_tool], # Add SQL tool so that the agent can query for the schema details.
description="Agent that answers questions using relevant articles from the database.",
instructions=(
"Whenever a question is provided, the agent will retrieve the top 4 most "
"related articles from the database using PgVector as its knowledge base, "
"and these results are then used to form the answer. "
"Note: The 'articles' table schema is as follows - created_at: timestamp, "
"title: text, embedding: vector, content: text, published_date: date, "
"authors: text, id: uuid. If you need further details about the table columns, "
"you can use the SQL tool's 'describe_table' function. "
"Refer to the [SQL Toolkits docs](https://docs.agno.com/tools/toolkits/sql) for guidance."
),
markdown=True,
debug_mode=True,
show_tool_calls=True,
)