diff --git a/examples/amazon_s3_embedding/README.md b/examples/amazon_s3_embedding/README.md index 66bf5fa3..3273716d 100644 --- a/examples/amazon_s3_embedding/README.md +++ b/examples/amazon_s3_embedding/README.md @@ -37,12 +37,6 @@ Install dependencies: pip install -e . ``` -Setup: - -```sh -cocoindex setup main.py -``` - Run: ```sh diff --git a/examples/amazon_s3_embedding/main.py b/examples/amazon_s3_embedding/main.py index b3740583..fd23654d 100644 --- a/examples/amazon_s3_embedding/main.py +++ b/examples/amazon_s3_embedding/main.py @@ -2,6 +2,7 @@ from psycopg_pool import ConnectionPool import cocoindex import os +from typing import Any @cocoindex.transform_flow() @@ -22,7 +23,7 @@ def text_to_embedding( @cocoindex.flow_def(name="AmazonS3TextEmbedding") def amazon_s3_text_embedding_flow( flow_builder: cocoindex.FlowBuilder, data_scope: cocoindex.DataScope -): +) -> None: """ Define an example flow that embeds text from Amazon S3 into a vector database. """ @@ -72,7 +73,7 @@ def amazon_s3_text_embedding_flow( ) -def search(pool: ConnectionPool, query: str, top_k: int = 5): +def search(pool: ConnectionPool, query: str, top_k: int = 5) -> list[dict[str, Any]]: # Get the table name, for the export target in the amazon_s3_text_embedding_flow above. table_name = cocoindex.utils.get_target_default_name( amazon_s3_text_embedding_flow, "doc_embeddings" @@ -95,9 +96,11 @@ def search(pool: ConnectionPool, query: str, top_k: int = 5): ] -def _main(): +def _main() -> None: # Initialize the database connection pool. pool = ConnectionPool(os.getenv("COCOINDEX_DATABASE_URL")) + + amazon_s3_text_embedding_flow.setup() with cocoindex.FlowLiveUpdater(amazon_s3_text_embedding_flow): # Run queries in a loop to demonstrate the query capabilities. while True: diff --git a/examples/amazon_s3_embedding/pyproject.toml b/examples/amazon_s3_embedding/pyproject.toml index c005d4e0..2fa97919 100644 --- a/examples/amazon_s3_embedding/pyproject.toml +++ b/examples/amazon_s3_embedding/pyproject.toml @@ -3,7 +3,7 @@ name = "amazon-s3-text-embedding" version = "0.1.0" description = "Simple example for cocoindex: build embedding index based on Amazon S3 files." requires-python = ">=3.11" -dependencies = ["cocoindex[embeddings]>=0.1.52", "python-dotenv>=1.0.1"] +dependencies = ["cocoindex[embeddings]>=0.1.57", "python-dotenv>=1.0.1"] [tool.setuptools] packages = [] diff --git a/examples/image_search/README.md b/examples/image_search/README.md index 017fc1fc..749c0bac 100644 --- a/examples/image_search/README.md +++ b/examples/image_search/README.md @@ -29,7 +29,6 @@ We appreciate a star ⭐ at [CocoIndex Github](https://github.com/cocoindex-io/c - Run Backend ``` - cocoindex setup main.py uvicorn main:app --reload --host 0.0.0.0 --port 8000 ``` diff --git a/examples/image_search/main.py b/examples/image_search/main.py index 629acad2..2ce30b9d 100644 --- a/examples/image_search/main.py +++ b/examples/image_search/main.py @@ -84,9 +84,11 @@ def image_object_embedding_flow( @asynccontextmanager -async def lifespan(app: FastAPI): +async def lifespan(app: FastAPI) -> None: load_dotenv() cocoindex.init() + image_object_embedding_flow.setup(report_to_stdout=True) + app.state.qdrant_client = QdrantClient(url=QDRANT_URL, prefer_grpc=True) # Start updater diff --git a/examples/image_search/pyproject.toml b/examples/image_search/pyproject.toml index f24a1189..d4bfc3a9 100644 --- a/examples/image_search/pyproject.toml +++ b/examples/image_search/pyproject.toml @@ -4,7 +4,7 @@ version = "0.1.0" description = "Simple example for cocoindex: build embedding index based on images." requires-python = ">=3.11" dependencies = [ - "cocoindex>=0.1.52", + "cocoindex>=0.1.57", "python-dotenv>=1.0.1", "fastapi>=0.100.0", "torch>=2.0.0",