惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Schneier on Security
F
Fortinet All Blogs
B
Blog
GbyAI
GbyAI
P
Proofpoint News Feed
量子位
The Register - Security
The Register - Security
宝玉的分享
宝玉的分享
大猫的无限游戏
大猫的无限游戏
云风的 BLOG
云风的 BLOG
V
Visual Studio Blog
B
Blog RSS Feed
WordPress大学
WordPress大学
Recorded Future
Recorded Future
Recent Announcements
Recent Announcements
V
Vulnerabilities – Threatpost
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
Secure Thoughts
雷峰网
雷峰网
Stack Overflow Blog
Stack Overflow Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Webroot Blog
Webroot Blog
AWS News Blog
AWS News Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
The GitHub Blog
The GitHub Blog
爱范儿
爱范儿
O
OpenAI News
月光博客
月光博客
H
Hacker News: Front Page
S
Security Affairs
W
WeLiveSecurity
The Hacker News
The Hacker News
aimingoo的专栏
aimingoo的专栏
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Help Net Security
Help Net Security
MongoDB | Blog
MongoDB | Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
D
Docker
T
The Blog of Author Tim Ferriss
Spread Privacy
Spread Privacy
Blog — PlanetScale
Blog — PlanetScale
J
Java Code Geeks
S
Securelist
Microsoft Azure Blog
Microsoft Azure Blog
TaoSecurity Blog
TaoSecurity Blog
T
Threat Research - Cisco Blogs
M
MIT News - Artificial intelligence
A
About on SuperTechFans

Supabase Blog

AI Agents Know About Supabase. They Don't Always Use It Right. Custom OIDC Providers for Supabase Auth 100,000 GitHub stars Supabase docs over SSH Navigating Regional Network Blocks Supabase Joins the Stripe Projects Developer Preview Log Drains: Now available on Pro Supabase Storage: major performance, security, and reliability updates Supabase incident on February 12, 2026 Hydra joins Supabase X / Twitter OAuth 2.0 is now available for Supabase Auth BKND joins Supabase Supabase is now an official Claude connector Supabase PrivateLink is now available Introducing: Postgres Best Practices When to use Read Replicas vs. bigger compute Introducing TRAE SOLO integration with Supabase Supabase Security Retro: 2025 Sync Stripe Data to Your Supabase Database in One Click Building ChatGPT Apps with Supabase Edge Functions and mcp-use Own Your Observability: Supabase Metrics API Introducing iceberg-js: A JavaScript Client for Apache Iceberg Introducing Supabase for Platforms Adding Async Streaming to Postgres Foreign Data Wrappers Build "Sign in with Your App" using Supabase Auth Introducing Seven New Email Templates for Supabase Auth The new Supabase power for Kiro Introducing Supabase ETL Introducing Analytics Buckets Introducing Vector Buckets Snap, Inc. Launches Snap Cloud, Powered by Supabase Triplit joins Supabase Supabase Series E 1000 Y Combinator Founders Choose Supabase gm 👋 web3, welcome aboard to Sign in with Web3 (Solana, Ethereum) Announcing the Supabase Remote MCP Server Enterprise speed, enterprise standards with Bolt Cloud + Supabase PostgREST 13 Lovable Cloud + Supabase: The Default Platform for AI Builders Processing large jobs with Edge Functions, Cron, and Queues Defense in Depth for MCP Servers OrioleDB Patent: now freely available to the Postgres community Supabase Launch Week 15 Hackathon Winner Announcement The Vibe Coder's Guide to Supabase Environments Testing for Vibe Coders: From Zero to Production Confidence The Vibe Coding Master Checklist Vibe Coding: Best Practices for Prompting Supabase Auth: Build vs. Buy Top 10 Launches of Launch Week 15 Supabase Launch Week 15 Hackathon Storage: 10x Larger Uploads, 3x Cheaper Cached Egress, and 2x Egress Quota Persistent Storage and 97% Faster Cold Starts for Edge Functions Algolia Connector for Supabase New Observability Features in Supabase Improved Security Controls and A New Home for Security Introducing Branching 2.0 Stripe-To-Postgres Sync Engine as standalone Library Supabase Analytics Buckets with Iceberg Support Create a Supabase backend using Figma Make Introducing JWT Signing Keys Supabase UI: Platform Kit Build a Personalized AI Assistant with Postgres Announcing Multigres: Vitess for Postgres Building on open table formats Open Data Standards: Postgres, OTel, and Iceberg Simplifying back-end complexity with Supabase Data APIs PostgreSQL Event Triggers without superuser access Top 10 Launches of Launch Week 14 Supabase MCP Server Data API Routes to Nearest Read Replica Declarative Schemas for Simpler Database Management Realtime: Broadcast from Database Keeping Tabs on What's New in Supabase Studio Edge Functions: Deploy from the Dashboard + Deno 2.1 Automatic Embeddings in Postgres Introducing the Supabase UI Library Supabase Auth: Bring Your Own Clerk Postgres Language Server: Initial Release Migrating from Fauna to Supabase Migrating from the MongoDB Data API to Supabase Dedicated Poolers Postgres as a Graph Database: (Ab)using pgRouting AI Hackathon at Y Combinator Calendars in Postgres using Foreign Data Wrappers Supabase Launch Week 13 Hackathon Winners How to Hack the Base! Running Durable Workflows in Postgres using DBOS database.build v2: Bring-your-own-LLM Restore to a New Project Hack the Base! with Supabase Top 10 Launches of Launch Week 13 Supabase Queues High Performance Disk Supabase Cron Supabase CLI v2: Config as Code Supabase Edge Functions: Introducing Background Tasks, Ephemeral Storage, and WebSockets Supabase AI Assistant v2 OrioleDB Public Alpha Executing Dynamic JavaScript Code on Supabase with Edge Functions ClickHouse Partnership, improved Postgres Replication, and Disk Management
Implementing semantic image search with Amazon Titan and Supabase Vector
Thor Schaeff · 2024-03-26 · via Supabase Blog

Implementing semantic image search with Amazon Titan and Supabase Vector

Amazon Bedrock is a fully managed service that offers a choice of high-performing foundation models (FMs) from leading AI companies like AI21 Labs, Anthropic, Cohere, Meta, Mistral AI, Stability AI, and Amazon. Each model is accessible through a common API which implements a broad set of features to help build generative AI applications with security, privacy, and responsible AI in mind.

Amazon Titan is a family of foundation models (FMs) for text and image generation, summarization, classification, open-ended Q&A, information extraction, and text or image search.

In this post we'll look at how we can get started with Amazon Bedrock and Supabase Vector in Python using the Amazon Titan multimodal model and the vecs client.

You can find the full application code as a Python Poetry project on GitHub.

Poetry provides packaging and dependency management for Python. If you haven't already, install poetry via pip:

Then initialize a new project:


_10

poetry new aws_bedrock_image_search


Spin up a Postgres Database with pgvector#

If you haven't already, head over to database.new and create a new project. Every Supabase project comes with a full Postgres database and the pgvector extension preconfigured.

When creating your project, make sure to note down your database password as you will need it to construct the DB_URL in the next step.

You can find the database connection string in your Supabase Dashboard project connect page. Select "Use connection pooling" with Mode: Session for a direct connection to your Postgres database. It will look something like this:


_10

postgresql://postgres.[PROJECT-REF]:[YOUR-PASSWORD]@aws-0-[REGION].pooler.supabase.com:5432/postgres


We will need to add the following dependencies to our project:

  • vecs: Supabase Vector Python Client.
  • boto3: AWS SDK for Python.
  • matplotlib: for displaying our image result.


_10

poetry add vecs boto3 matplotlib


At the top of your main python script, import the dependencies and store your DB URL from above in a variable:


_10

import sys

_10

import boto3

_10

import vecs

_10

import json

_10

import base64

_10

from matplotlib import pyplot as plt

_10

from matplotlib import image as mpimg

_10

from typing import Optional

_10

_10

DB_CONNECTION = "postgresql://postgres.[PROJECT-REF]:[YOUR-PASSWORD]@aws-0-[REGION].pooler.supabase.com:5432/postgres"


Next, get the credentials to your AWS account and instantiate the boto3 client:


_10

bedrock_client = boto3.client(

_10

'bedrock-runtime',

_10

region_name='us-west-2',

_10

# Credentials from your AWS account

_10

aws_access_key_id='<replace_your_own_credentials>',

_10

aws_secret_access_key='<replace_your_own_credentials>',

_10

aws_session_token='<replace_your_own_credentials>',

_10

)


In the root of your project, create a new folder called images and add some images. You can use the images from the example project on GitHub or you can find license free images on unsplash.

To send images to the Amazon Bedrock API we need to need to encode them as base64 strings. Create the following helper methods:


_44

def readFileAsBase64(file_path):

_44

"""Encode image as base64 string."""

_44

try:

_44

with open(file_path, "rb") as image_file:

_44

input_image = base64.b64encode(image_file.read()).decode("utf8")

_44

return input_image

_44

except:

_44

print("bad file name")

_44

sys.exit(0)

_44

_44

_44

def construct_bedrock_image_body(base64_string):

_44

"""Construct the request body.

_44

_44

https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-titan-embed-mm.html

_44

"""

_44

return json.dumps(

_44

{

_44

"inputImage": base64_string,

_44

"embeddingConfig": {"outputEmbeddingLength": 1024},

_44

}

_44

)

_44

_44

_44

def get_embedding_from_titan_multimodal(body):

_44

"""Invoke the Amazon Titan Model via API request."""

_44

response = bedrock_client.invoke_model(

_44

body=body,

_44

modelId="amazon.titan-embed-image-v1",

_44

accept="application/json",

_44

contentType="application/json",

_44

)

_44

_44

response_body = json.loads(response.get("body").read())

_44

print(response_body)

_44

return response_body["embedding"]

_44

_44

_44

def encode_image(file_path):

_44

"""Generate embedding for the image at file_path."""

_44

base64_string = readFileAsBase64(file_path)

_44

body = construct_bedrock_image_body(base64_string)

_44

emb = get_embedding_from_titan_multimodal(body)

_44

return emb


Next, create a seed method, which will create a new Supabase Vector Collection, generate embeddings for your images, and upsert the embeddings into your database:


_40

def seed():

_40

# create vector store client

_40

vx = vecs.create_client(DB_CONNECTION)

_40

_40

# get or create a collection of vectors with 1024 dimensions

_40

images = vx.get_or_create_collection(name="image_vectors", dimension=1024)

_40

_40

# Generate image embeddings with Amazon Titan Model

_40

img_emb1 = encode_image('./images/one.jpg')

_40

img_emb2 = encode_image('./images/two.jpg')

_40

img_emb3 = encode_image('./images/three.jpg')

_40

img_emb4 = encode_image('./images/four.jpg')

_40

_40

# add records to the *images* collection

_40

images.upsert(

_40

records=[

_40

(

_40

"one.jpg", # the vector's identifier

_40

img_emb1, # the vector. list or np.array

_40

{"type": "jpg"} # associated metadata

_40

), (

_40

"two.jpg",

_40

img_emb2,

_40

{"type": "jpg"}

_40

), (

_40

"three.jpg",

_40

img_emb3,

_40

{"type": "jpg"}

_40

), (

_40

"four.jpg",

_40

img_emb4,

_40

{"type": "jpg"}

_40

)

_40

]

_40

)

_40

print("Inserted images")

_40

_40

# index the collection for fast search performance

_40

images.create_index()

_40

print("Created index")


Add this method as a script in your pyproject.toml file:


_10

[tool.poetry.scripts]

_10

seed = "image_search.main:seed"

_10

search = "image_search.main:search"


After activating the virtual environtment with poetry shell you can now run your seed script via poetry run seed. You can inspect the generated embeddings in your Supabase Dashboard by visiting the Table Editor, selecting the vecs schema, and the image_vectors table.

Perform an image search from a text query#

With Supabase Vector we can easily query our embeddings. We can use either an image as the search input or alternatively we can generate an embedding from a string input and use that as the query input:


_28

def search(query_term: Optional[str] = None):

_28

if query_term is None:

_28

query_term = sys.argv[1]

_28

_28

# create vector store client

_28

vx = vecs.create_client(DB_CONNECTION)

_28

images = vx.get_or_create_collection(name="image_vectors", dimension=1024)

_28

_28

# Encode text query

_28

text_emb = get_embedding_from_titan_multimodal(json.dumps(

_28

{

_28

"inputText": query_term,

_28

"embeddingConfig": {"outputEmbeddingLength": 1024},

_28

}

_28

))

_28

_28

# query the collection filtering metadata for "type" = "jpg"

_28

results = images.query(

_28

data=text_emb, # required

_28

limit=1, # number of records to return

_28

filters={"type": {"$eq": "jpg"}}, # metadata filters

_28

)

_28

result = results[0]

_28

print(result)

_28

plt.title(result)

_28

image = mpimg.imread('./images/' + result)

_28

plt.imshow(image)

_28

plt.show()


By limiting the query to one result, we can show the most relevant image to the user. Finally we use matplotlib to show the image result to the user.

That's it, go ahead and test it out by running poetry run search and you will be presented with an image of a "bike in front of a red brick wall".

With just a couple of lines of Python you are able to implement image search as well as reverse image search using the Amazon Titan multimodal model and Supabase Vector.