Documentation Index
Fetch the complete documentation index at: https://spacesail.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
The JSON Reader with asynchronous processing allows you to handle JSON files efficiently and integrate them with knowledge bases.
Code
examples/concepts/knowledge/readers/json_reader_async.py
import json
import asyncio
from pathlib import Path
from agno.agent import Agent
from agno.knowledge.knowledge import Knowledge
from agno.knowledge.reader.json_reader import JSONReader
from agno.vectordb.pgvector import PgVector
db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"
# Create test JSON data
json_path = Path("tmp/test.json")
json_path.parent.mkdir(exist_ok=True)
test_data = {
"users": [
{"id": 1, "name": "John Doe", "role": "Developer"},
{"id": 2, "name": "Jane Smith", "role": "Designer"}
],
"project": "Knowledge Base System"
}
json_path.write_text(json.dumps(test_data, indent=2))
knowledge = Knowledge(
vector_db=PgVector(
table_name="json_documents",
db_url=db_url,
),
)
agent = Agent(
knowledge=knowledge,
search_knowledge=True,
)
async def main():
# Add JSON content to knowledge base
await knowledge.add_content_async(
path=json_path,
reader=JSONReader(),
)
# Query the knowledge base
await agent.aprint_response(
"What information is available about the users?",
markdown=True
)
if __name__ == "__main__":
asyncio.run(main())
Usage
Create a virtual environment
Open the Terminal and create a python virtual environment.python3 -m venv .venv
source .venv/bin/activate
Install libraries
pip install -U sqlalchemy psycopg pgvector agno openai
Set environment variables
export OPENAI_API_KEY=xxx
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
Run Agent
python examples/concepts/knowledge/readers/json_reader_async.py
Params
| Parameter | Type | Default | Description |
path | Path | Required | Path to JSON file to read |
chunk | bool | False | Whether to chunk the documents (overrides base Reader default) |