Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions examples/amazon_s3_embedding/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@ Install dependencies:
pip install -e .
```

Setup:

```sh
cocoindex setup main.py
```

Run:

```sh
Expand Down
9 changes: 6 additions & 3 deletions examples/amazon_s3_embedding/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from psycopg_pool import ConnectionPool
import cocoindex
import os
from typing import Any


@cocoindex.transform_flow()
Expand All @@ -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.
"""
Expand Down Expand Up @@ -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"
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion examples/amazon_s3_embedding/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
1 change: 0 additions & 1 deletion examples/image_search/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down
4 changes: 3 additions & 1 deletion examples/image_search/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/image_search/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down