22from psycopg_pool import ConnectionPool
33import cocoindex
44import os
5+ from typing import Any
56
67
78@cocoindex .transform_flow ()
@@ -22,7 +23,7 @@ def text_to_embedding(
2223@cocoindex .flow_def (name = "AmazonS3TextEmbedding" )
2324def amazon_s3_text_embedding_flow (
2425 flow_builder : cocoindex .FlowBuilder , data_scope : cocoindex .DataScope
25- ):
26+ ) -> None :
2627 """
2728 Define an example flow that embeds text from Amazon S3 into a vector database.
2829 """
@@ -72,7 +73,7 @@ def amazon_s3_text_embedding_flow(
7273 )
7374
7475
75- def search (pool : ConnectionPool , query : str , top_k : int = 5 ):
76+ def search (pool : ConnectionPool , query : str , top_k : int = 5 ) -> list [ dict [ str , Any ]] :
7677 # Get the table name, for the export target in the amazon_s3_text_embedding_flow above.
7778 table_name = cocoindex .utils .get_target_default_name (
7879 amazon_s3_text_embedding_flow , "doc_embeddings"
@@ -95,9 +96,11 @@ def search(pool: ConnectionPool, query: str, top_k: int = 5):
9596 ]
9697
9798
98- def _main ():
99+ def _main () -> None :
99100 # Initialize the database connection pool.
100101 pool = ConnectionPool (os .getenv ("COCOINDEX_DATABASE_URL" ))
102+
103+ amazon_s3_text_embedding_flow .setup ()
101104 with cocoindex .FlowLiveUpdater (amazon_s3_text_embedding_flow ):
102105 # Run queries in a loop to demonstrate the query capabilities.
103106 while True :
0 commit comments