This example shows how to add content from a Google Cloud Storage (GCS) bucket to your knowledge base. This allows you to process documents stored in Google Cloud without downloading them locally.

Code

gcs.py
"""This cookbook shows how to add content from a GCS bucket to the knowledge base.
1. Run: `python cookbook/agent_concepts/knowledge/12_from_gcs.py` to run the cookbook
"""

import asyncio

from agno.agent import Agent
from agno.db.postgres import PostgresDb
from agno.knowledge.knowledge import Knowledge
from agno.knowledge.remote_content.remote_content import GCSContent
from agno.vectordb.pgvector import PgVector

contents_db = PostgresDb(
    db_url="postgresql+psycopg://ai:ai@localhost:5532/ai",
    knowledge_table="knowledge_contents",
)

# Create Knowledge Instance
knowledge = Knowledge(
    name="Basic SDK Knowledge Base",
    description="Agno 2.0 Knowledge Implementation",
    contents_db=contents_db,
    vector_db=PgVector(
        table_name="vectors", db_url="postgresql+psycopg://ai:ai@localhost:5532/ai"
    ),
)

# Add from GCS
asyncio.run(
    knowledge.add_content_async(
        name="GCS PDF",
        remote_content=GCSContent(
            bucket_name="thai-recepies", blob_name="ThaiRecipes.pdf"
        ),
        metadata={"remote_content": "GCS"},
    )
)


agent = Agent(
    name="My Agent",
    description="Agno 2.0 Agent Implementation",
    knowledge=knowledge,
    search_knowledge=True,
    debug_mode=True,
)

agent.print_response(
    "What is the best way to make a Thai curry?",
    markdown=True,
)

Usage

1

Install libraries

pip install -U agno sqlalchemy psycopg pgvector google-cloud-storage
2

Configure Google Cloud credentials

Set up your GCS credentials using one of these methods:
  • Service Account Key: Set GOOGLE_APPLICATION_CREDENTIALS environment variable
  • gcloud CLI: gcloud auth application-default login
  • Workload Identity (if running on Google Cloud)
3

Run PgVector

docker run -d \
  -e POSTGRES_DB=ai \
  -e POSTGRES_USER=ai \
  -e POSTGRES_PASSWORD=ai \
  -e PGDATA=/var/lib/postgresql/data/pgdata \
  -v pgvolume:/var/lib/postgresql/data \
  -p 5532:5432 \
  --name pgvector \
  agno/pgvector:16
4

Run the example

python cookbook/knowledge/basic_operations/07_from_gcs.py

Params

ParameterTypeDefaultDescription
bucket_namestr-Name of the GCS bucket containing the file.
blob_namestr-Name of the blob (file) within the bucket.
prefixOptional[str]-Path prefix for organizing files in the bucket.
bucketOptional[Any]-Pre-configured GCS bucket object.