[ pl4stik @ 15.03.2025. 15:13 ] @
Pozdrav,

Suzdrzite se molim vas od grubosti prvi put pisem py
Pre 2 dana poceh malo da ucim Py i dadoh sebi zadatak da napravim kao projekat sa REST, GraphQL, OAuth2/JWT, SQL i vector search. Za bazu sam izabrao Postgre sa pgvector (ankane/pgvector). Embeding model je all-MiniLM-L6-v2.
Code:
https://github.com/cikavelja/py-gql-ai

I ok radi ali kad pokusam paralelno da insertujem jednom 50 redova u bazu odradi a ako pokusam opet dobijem sledece i to bez greske na clijentu.

sqlalchemy.exc.TimeoutError: QueuePool limit of size 20 overflow 40 reached, connection timed out, timeout 60.00 (Background on this error at: https://sqlalche.me/e/20/3o7r)


Interesuje me jel neko resavao ovako nesto? Jel sqlalchemy ok po vama?

Ovako radim insert

Code:

import asyncio
import aiohttp
import json

API_URL = "http://127.0.0.1:8000/graphql"

ARTICLES = [
    ("AI in Healthcare", "AI is transforming the healthcare industry, improving diagnostics and patient care."),
    ("Blockchain and Finance", "Blockchain ensures secure financial transactions and decentralized finance (DeFi)."),
    ("Space Exploration", "Space missions to Mars and beyond are advancing science and technology."),
    ("Quantum Computing", "Quantum computers solve complex calculations using qubits."),
    ("Cybersecurity Trends", "AI-driven cybersecurity is crucial in protecting sensitive data."),
    ("Renewable Energy", "Solar, wind, and hydro power are key in addressing climate change."),
    ("5G Technology", "5G enables high-speed internet and low-latency connectivity."),
    ("Virtual Reality", "VR enhances gaming, education, and workplace collaboration."),
    ("Autonomous Vehicles", "Self-driving cars leverage AI for navigation and safety."),
    ("IoT and Smart Homes", "IoT devices automate homes for better convenience and efficiency."),
    ("Cloud Computing", "Cloud platforms provide scalable infrastructure for businesses."),
    ("Artificial General Intelligence", "AGI aims to create machines with human-like reasoning."),
    ("E-commerce Growth", "AI optimizes online shopping experiences and logistics."),
    ("Cryptocurrency Adoption", "Bitcoin and Ethereum are revolutionizing global finance."),
    ("Biotechnology Innovations", "Gene editing and synthetic biology are transforming medicine."),
    ("Ethical AI", "Ensuring fairness and transparency in AI decision-making."),
    ("Metaverse and Virtual Worlds", "The metaverse is redefining digital interaction."),
    ("Digital Transformation", "AI and big data drive digital innovation."),
    ("Neural Networks", "Deep learning enables human-like pattern recognition."),
    ("Social Media Impact", "Platforms influence communication and marketing strategies."),
    ("Natural Language Processing", "NLP helps machines understand and generate human language."),
    ("Edge Computing", "Processing data closer to devices reduces latency."),
    ("Robotics in Manufacturing", "Industrial robots improve efficiency and precision."),
    ("Climate Change Solutions", "Technology aids in combating environmental issues."),
    ("Big Data Analytics", "Data-driven decision-making powers modern businesses."),
    ("AI-powered Chatbots", "Chatbots automate customer service efficiently."),
    ("Genomics and Personalized Medicine", "Advances in DNA sequencing improve healthcare."),
    ("Augmented Reality", "AR transforms retail, education, and entertainment."),
    ("Quantum Cryptography", "Enhancing security through quantum encryption."),
    ("Self-Learning AI", "AI models improve without human intervention."),
    ("Cyber Threat Intelligence", "Organizations use AI to detect and prevent cyber threats."),
    ("Food Tech Innovations", "Lab-grown meat and alternative proteins are reshaping food."),
    ("AI in Agriculture", "AI optimizes farming techniques and crop yields."),
    ("Data Privacy Regulations", "GDPR and policies safeguard user data."),
    ("AI in Finance", "AI-driven trading and risk management strategies."),
    ("Biometric Authentication", "Face and fingerprint recognition for security."),
    ("Wearable Technology", "Smartwatches and fitness trackers monitor health."),
    ("Self-Healing Materials", "Materials that repair themselves reduce maintenance."),
    ("AI and Creativity", "AI-generated art and music challenge creativity."),
    ("Space Tourism", "Commercial space travel is becoming a reality."),
    ("Personalized AI Assistants", "Voice assistants adapt to user preferences."),
    ("Biodegradable Plastics", "Eco-friendly plastics reduce environmental impact."),
    ("AI in Drug Discovery", "AI accelerates pharmaceutical research."),
    ("Autonomous Drones", "Drones revolutionize delivery and surveillance."),
    ("AI in Education", "Personalized learning powered by AI."),
    ("3D Printing Innovations", "Transforming manufacturing and medical applications."),
    ("AI-powered Code Generation", "AI assists developers with coding suggestions."),
]

async def insert_article(session, title, content):
    mutation = {
        "query": """
        mutation CreateArticle($title: String!, $content: String!) {
            createArticle(title: $title, content: $content) {
                id
                title
                content
            }
        }
        """,
        "variables": {"title": title, "content": content}
    }
    
    async with session.post(API_URL, json=mutation) as response:
        if response.status == 200:
            print(f"Inserted: {title}")
        else:
            print(f"Failed to insert: {title} - {response.status}")

async def main():
    async with aiohttp.ClientSession() as session:
        tasks = [insert_article(session, title, content) for title, content in ARTICLES]
        await asyncio.gather(*tasks)
    print("All articles inserted successfully.")

if __name__ == "__main__":
    asyncio.run(main())