Skip to content

Enhance Image Search Example - Live Update #459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

par4m
Copy link
Contributor

@par4m par4m commented May 9, 2025

Enhances Image Search Example by adding Live Update

  • Threading: Runs the live updater in the background,separate from FastAPI’s main thread.
  • Asyncio: Runs the async updater logic

Copy link
Member

@badmonster0 badmonster0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For get_image_caption, we can consider enable cache:

https://cocoindex.io/docs/core/custom_function#parameters-for-custom-functions

print("[LiveUpdater] Thread starting...")
asyncio.run(updater_coroutine())
print("[LiveUpdater] Thread finished.")
thread = threading.Thread(target=run_updater, daemon=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to create a separate thread. I think this is sufficient:

app.state.live_updater = cocoindex.FlowLiveUpdater(image_object_embedding_flow)

It will use a background thread (with Rust runtime) to watch changes automatically
(You can call app.state.live_updater.abort() to stop it, but usually not necessary for a long-running process)

@badmonster0
Copy link
Member

With this change, the README can also be simplified. We don't need to run cocoindex update separately:

python main.py cocoindex update

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants