Skip to content

Commit 19d15ee

Browse files
committed
Fix lancedb_hybrid_execution parameter and update prompts
1 parent b7a8adb commit 19d15ee

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

02-use-cases/data_analysis_with_datalake/prompts.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,13 @@
5151
- **何时使用**:
5252
1. 当用户描述画面的**视觉特征**时。
5353
2. 当用户描述**抽象概念**或**剧情氛围**,且无法通过简单的 Genre 字段过滤时。
54-
- **Filters 语法**:
55-
- 仅接受 SQL `WHERE` 子句格式。
56-
- 字符串必须用单引号。
57-
- `released_year` 必须用单引号。
58-
- 示例:`"director = 'Ang Lee' AND released_year > '2000'"`
54+
- **参数说明**:
55+
- `query_text`: 搜索文本描述(必填),如海报视觉特征或语义概念
56+
- `filters`: SQL WHERE 子句格式的过滤条件(可选),如 `"director LIKE '%Nolan%' AND imdb_rating > 7.0"`
57+
- `select`: 要返回的字段列表(可选),默认 `["Series_Title", "poster_precision_link"]`
58+
- `limit`: 返回结果数量(可选),默认 10
59+
- **调用示例**:
60+
`lancedb_hybrid_execution(query_text="poster with animals", filters="director LIKE '%Ang Lee%' AND imdb_rating > 7.0", select=["series_title", "poster_precision_link"], limit=10)`
5961
6062
#### 3. [video_generate] (视频生成)
6163
- **定义**:基于 Prompt 或图片生成视频。
@@ -80,7 +82,7 @@
8082
#### Q3: Ang Lee 评分超过 7 分的电影中,有哪个电影海报中含有动物? (混合检索)
8183
**User:** "Ang Lee 评分超过 7 分的电影中,有哪个电影海报中含有动物?"
8284
**Thought:** 用户查询包含对电影海报内容的视觉描述(“含有动物”),需进行语义/视觉搜索,同时包含元数据过滤(导演和评分)。
83-
**Action:** `lancedb_hybrid_execution({"query_text": "poster with animals", "filters": "director LIKE '%Ang Lee%' AND imdb_rating > 7.0", "select": ["series_title", "poster_precision_link"], "limit": 10})`
85+
**Action:** `lancedb_hybrid_execution(query_text="poster with animals", filters="director LIKE '%Ang Lee%' AND imdb_rating > 7.0", select=["series_title", "poster_precision_link"], limit=10)`
8486
8587
#### Q4: 把《Life of Pi》的电影海报,变成视频 (已知实体 -> 视频)
8688
**User:** "把《Life of Pi》的电影海报,变成视频"
@@ -99,7 +101,7 @@
99101
1. 用户未指定电影名,而是描述画面内容(“红色跑车”)。
100102
2. 这是**视觉检索**任务,必须使用 LanceDB 查找符合描述的海报。
101103
3. 获取检索结果后,调用视频生成工具。
102-
**Action:** `lancedb_hybrid_execution({"query_text": "poster with a red sports car", "select": ["series_title", "poster_precision_link"], "limit": 1})`
104+
**Action:** `lancedb_hybrid_execution(query_text="poster with a red sports car", select=["series_title", "poster_precision_link"], limit=1)`
103105
**Observation:** `[{"series_title": "Ford v Ferrari", "poster_precision_link": "https://.../fvf.jpg"}]`
104106
**Thought:** 已找到符合描述的电影《Ford v Ferrari》,现在生成视频。
105107
**Action:** `video_generate(params=[{"video_name": "car_movie.mp4", "first_frame": "https://.../fvf.jpg", "prompt": "红色跑车在赛道上飞驰,引擎轰鸣,速度感。"}], batch_size=1)`

02-use-cases/data_analysis_with_datalake/tools/lancedb_hybrid_execution.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import json
3+
from typing import Optional
34

45
from rich.console import Console
56
import pandas as pd
@@ -11,24 +12,19 @@
1112
# Import utility functions
1213
from .utils import get_multimodal_text_vector as _get_text_vector
1314

14-
def lancedb_hybrid_execution(sql_query: str, user_question: str = "") -> str:
15-
console.print(f"[lancedb_hybrid_execution] Inputs: sql_query={sql_query!r}, user_question={user_question!r}")
16-
try:
17-
params = json.loads(sql_query)
18-
except Exception:
19-
return json.dumps({"error": "Invalid query format: expected JSON"}, ensure_ascii=False)
15+
16+
def lancedb_hybrid_execution(query_text: str, filters: str = "", select: Optional[list] = None, limit: int = 10) -> str:
17+
console.print(f"[lancedb_hybrid_execution] Inputs: query_text={query_text!r}, filters={filters!r}")
2018

2119
# open table
2220
tbl, err = lancedb_manager.open_table()
2321
if err:
2422
return json.dumps({"error": err}, ensure_ascii=False)
2523

2624
# parse params
27-
query_text = params.get("query_text") or ""
2825
vector_col = "poster_embedding"
29-
limit = 1000
30-
select = params.get("select") or ["Series_Title", "poster_precision_link"]
31-
filters = params.get("filters") or ""
26+
if select is None:
27+
select = ["Series_Title", "poster_precision_link"]
3228

3329
# embed
3430
vec, v_err = _get_text_vector(query_text)

0 commit comments

Comments
 (0)