Code:
import os
from agno.agent import Agent
from agno.knowledge.csv import CSVKnowledgeBase
from agno.vectordb.pgvector import PgVector
from dotenv import load_dotenv
from agno.models.google import Gemini
from agno.embedder.google import GeminiEmbedder
from agno.document.chunking.fixed import FixedSizeChunking
from environs import Env
import vertexai
load_dotenv()
vertexai.init(project=“xxxx-xxxx-4xxx7”, location=“asia-south1”)
GOOGLE_API_KEY = os.getenv(‘GOOGLE_API_KEY’)
env = Env()
env.read_env()
db_url = env.str(“DB_URL”)
csv_path = “./knowledge/xyz.csv”
table_name = “chunks4” # Or whatever your current table name is
def create_knowledge_base(csv_path, table_name):
kb = CSVKnowledgeBase(
path=csv_path,
vector_db=PgVector(
table_name=table_name,
db_url=db_url,
embedder=GeminiEmbedder(api_key=GOOGLE_API_KEY),
),
chunking_strategy=FixedSizeChunking(chunk_size=512), # Removed chunk_overlap as per earlier fix
)
kb.load()
return kb
kb4 = create_knowledge_base(csv_path, table_name)
relocation_bot = Agent(
model=Gemini(
id=“gemini-1.5-pro-002”
),
role=“Strict Relocation Assistant”,
description=“…”,
instructions=[… ],
knowledge=kb4,
search_knowledge=True,
prevent_hallucinations=True,
)
Error:
ERROR Error processing document ‘relocation_benefits’: 401 UNAUTHENTICATED. {‘error’: {‘code’: 401, ‘message’: ‘API keys are not supported
by this API. Expected OAuth2 access token or other authentication credentials that assert a principal. , ‘status’: ‘UNAUTHENTICATED’, ‘details’: [{’@type’:
‘type.googleapis.com/google.rpc.ErrorInfo’, ‘reason’: ‘CREDENTIALS_MISSING’, ‘domain’: ‘googleapis.com’, ‘metadata’: {‘method’:
‘google.cloud.aiplatform.v1beta1.PredictionService.Predict’, ‘service’: ‘aiplatform.googleapiscom’}}]}}
I have recently moved from phi to agno, and I am getting this error while trying to load the knowledge base.
I am using the google api key, which is absolutely functional, but somehow I am getting the same error again and again 401, unauthenticated.
Could you please provide me with the appropriate solution for this?strong text