Skip to content

Commit b38d3b2

Browse files
authored
example: update examples to adopt setup API (#682)
1 parent 000fae8 commit b38d3b2

File tree

6 files changed

+11
-13
lines changed

6 files changed

+11
-13
lines changed

examples/amazon_s3_embedding/README.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,6 @@ Install dependencies:
3737
pip install -e .
3838
```
3939

40-
Setup:
41-
42-
```sh
43-
cocoindex setup main.py
44-
```
45-
4640
Run:
4741

4842
```sh

examples/amazon_s3_embedding/main.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from psycopg_pool import ConnectionPool
33
import cocoindex
44
import 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")
2324
def 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:

examples/amazon_s3_embedding/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "amazon-s3-text-embedding"
33
version = "0.1.0"
44
description = "Simple example for cocoindex: build embedding index based on Amazon S3 files."
55
requires-python = ">=3.11"
6-
dependencies = ["cocoindex[embeddings]>=0.1.52", "python-dotenv>=1.0.1"]
6+
dependencies = ["cocoindex[embeddings]>=0.1.57", "python-dotenv>=1.0.1"]
77

88
[tool.setuptools]
99
packages = []

examples/image_search/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ We appreciate a star ⭐ at [CocoIndex Github](https://github.com/cocoindex-io/c
2929

3030
- Run Backend
3131
```
32-
cocoindex setup main.py
3332
uvicorn main:app --reload --host 0.0.0.0 --port 8000
3433
```
3534

examples/image_search/main.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,11 @@ def image_object_embedding_flow(
8484

8585

8686
@asynccontextmanager
87-
async def lifespan(app: FastAPI):
87+
async def lifespan(app: FastAPI) -> None:
8888
load_dotenv()
8989
cocoindex.init()
90+
image_object_embedding_flow.setup(report_to_stdout=True)
91+
9092
app.state.qdrant_client = QdrantClient(url=QDRANT_URL, prefer_grpc=True)
9193

9294
# Start updater

examples/image_search/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version = "0.1.0"
44
description = "Simple example for cocoindex: build embedding index based on images."
55
requires-python = ">=3.11"
66
dependencies = [
7-
"cocoindex>=0.1.52",
7+
"cocoindex>=0.1.57",
88
"python-dotenv>=1.0.1",
99
"fastapi>=0.100.0",
1010
"torch>=2.0.0",

0 commit comments

Comments
 (0)