⚡ Live Interactive Code Sandbox: AI Dev Tool: Were gonna need a
▶️ Run Code
💳 Unlock Source Code ($5)
📝 Editable Code Sandbox
```python # AI Dev Tool: PostgreSQL Vector Search Extension with FastAPI and Bun # ===================================================================== from fastapi import FastAPI, HTTPException from fastapi.responses import JSONResponse from fastapi.requests import Request from pydantic import BaseModel from typing import List, Optional import psycopg2 import numpy as np from psycopg2 import Error from psycopg2.extras import DictCursor import logging # Initialize the FastAPI app app = FastAPI() # Define the PostgreSQL connection parameters POSTGRES_HOST = "localhost" POSTGRES_DB = "vector_search" POSTGRES_USER = "postgres" POSTGRES_PASSWORD = "password" # Define the Bun configuration BUN_HOST = "http://localhost:3000" # Define the logger logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) # Define the VectorSearchRequest model class VectorSearchRequest(BaseModel): """Vector search request model""" query: str limit: Optional[int] = 10 # Define the VectorSearchResponse model class VectorSearchResponse(BaseModel): """Vector search response model""" results: List[dict] # Create a PostgreSQL connection def create_connection(): """Create a PostgreSQL connection"""
🖥️ Interactive Execution Terminal Console
⚡ Ready! Click ▶️ Run Code to execute code in browser terminal...