Pgvector column names

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,
)

Hi @jeremy_of_course
Thanks for reaching out and for using Agno! I’ve looped in the right engineers to help with your question. We usually respond within 24 hours, but if this is urgent, just let us know, and we’ll do our best to prioritize it.
Appreciate your patience—we’ll get back to you soon! :smile:

Hey @jeremy_of_course

It sounds like PgVector might be defaulting to looking for a column named "name", likely because it doesn’t know which column contains the vector embeddings.

Try explicitly specifying the column name in your PgVector initialization like this:

vector_db = PgVector(
    db_url=db_url,
    table_name="articles",
    schema="public",
    column_name="embedding",  # Explicitly tell PgVector which column to use
    embedder=OpenAIEmbedder(api_key=openai_api_key),
    search_type=SearchType.hybrid,
)

This will confirm if the embedding column exists as expected.

Let me know if that helps!

The column_name parameter doesn’t exist for the PgVector class, thus this solution can’t possibly work.

1 Like

+1, I don’t see column_name in the PgVector class

Hi @robaetem and @tylertaewook ! PgVector column names are fixed. Would love to know the use cases for custom column name?

Thanks! Also let us know if there is any other issue here.

Hi @mustafa

For example, I’m using supabase postgres table schema like this where I store a 1536-dimension vector embedding in vector_embedding pgvector column. This gives further granular control on how we chunk, index, and retrieve chunks of information during RAG search.

create table public.source_file_chunks (
  id uuid not null default extensions.uuid_generate_v4 (),
  source_file_id uuid not null,
  chunk_index integer not null,
  content text not null,
  embed text not null,
  vector_embedding public.vector null,
  blocks jsonb null,
  created_at timestamp with time zone not null default CURRENT_TIMESTAMP,
  constraint source_file_chunks_pkey primary key (id),
  constraint uq_source_file_chunk unique (source_file_id, chunk_index),
  constraint source_file_chunks_source_file_id_fkey foreign KEY (source_file_id) references source_files (id) on delete CASCADE
) TABLESPACE pg_default;

So many of us use supabase for easy backend that eliminates the use of vector DBs thanks to pgvector columns. Would love more support and documentation on this!

(also posted on: Official Documentation & Support for Supabase Integration)

Hi @tylertaewook ! Thanks for sharing the use cases. I have forwarded it to the team and we shoul d have an update soon. @Monali Please add this to feature request

Will keep you updated on this!!

1 Like