FT.PROFILE
执行 FT.SEARCH、FT.AGGREGATE 或 FT.HYBRID 命令并收集性能信息
语法
FT.PROFILE index [LIMITED] QUERY query
引入版本:2.2.0
复杂度摘要:O(N)
应用 FT.SEARCH、FT.HYBRID 或 FT.AGGREGATE 命令来收集性能详细信息。使用方法请参见示例。
必需参数
index
是使用FT.CREATE 创建的索引的名称。
SEARCH | HYBRID | AGGREGATE
表示配置文件类型,FT.SEARCH、FT.HYBRID 或 FT.AGGREGATE。
LIMITED
删除任何 reader 迭代器的详细信息。
QUERY {query}
是查询字符串,发送到FT.SEARCH、FT.HYBRID 或FT.AGGREGATE。
NOCONTENT or LIMIT 0 0 to reduce the number of reply results, or LIMITED to not reply with details of reader iterators inside built-in unions, such as fuzzy or prefix iterators.
返回
[!NOTE] 此页面包含自 RediSearch v2.8.33、v2.10.26、v8.2.7 和 v8.4.3 起的最新配置文件输出。 RediSearch 版本和 RESP 协议版本之间的输出格式本身可能有所不同。
FT.PROFILE 返回一个两元素数组回复。第一个元素包含所提供的 FT.SEARCH、FT.HYBRID 或 FT.AGGREGATE 命令的结果。第二个元素包含有关查询创建、迭代器配置文件和结果处理器配置文件的信息。第二个元素的详细信息如下。
每个分片的配置文件
此部分包含每个分片的查询执行详细信息。当多个分片同时运行时,这些分片将被标记为 Shard #1、Shard #2 等。如果只有一个分片,则该标签将被省略。
| 返回的字段名 | 定义 |
|---|---|
Shard ID |
包含唯一分片 ID 的字符串。在 Redis 开源中,此标识符表示为节点 ID,并从 RedisModule_GetMyClusterID() API 接收。 (自 RediSearch v8.4.3 起可用) |
Total profile time |
查询的总运行时间(毫秒)。通常只需几毫秒。 |
Parsing time |
将查询及其参数解析为查询计划所花费的时间(毫秒)。通常只需几毫秒。 |
Pipeline creation time |
执行计划的创建时间(毫秒),包括迭代器、结果处理器和减速器的创建。通常,FT.SEARCH 或 FT.HYBRID 查询只需几毫秒,但 FT.AGGREGATE 查询预计需要更长的时间。 |
Total GIL time |
在多线程部署中,查询在执行过程中持有和等待 Redis 全局锁(简称 GIL)所花费的总时间(毫秒)。注意:该值仅在分片配置文件部分有效。 |
Warning |
查询执行期间发生的错误。 |
Internal cursor reads |
在集群模式下的分布式 AGGREGATE 查询期间,协调器从给定分片获取结果批次的次数。包括初始请求以及任何后续批量提取。 |
迭代器简介
本节包含索引迭代器信息,包括 Type、Query Type、Term(如果适用)、Time (ms)、Number of reading operations、Child iterator 和 Estimated number of matches 信息。每个迭代器代表查询计划每个部分的执行器,按执行计划嵌套。下面提到的操作类型(例如 UNION)应与提供的查询匹配。
倒排索引迭代器还包括它们所包含的元素数量。矢量迭代器包括附加的分析信息。请参阅下面的 关于向量迭代器配置文件的注释。
迭代器类型包括:
INTERSECT(和)与Child iteratorUNION(或)与Child iteratorNOT(-) 和Child iteratorChild iterator- 复合查询的子查询组件的详细信息。TEXT与TermTAG与TermNUMERIC与TermVECTORMETRIC - VECTOR DISTANCEGEO与TermEMPTYWILDCARDOPTIONALOPTIMIZER和Optimizer mode- 按数字字段排序的FT.SEARCH查询的查询优化包装器。在 DIALECT 4 中默认启用,或在WITHOUTCOUNT中明确启用。ID-LIST- 特定文档 ID 上的迭代器(使用INKEYS时出现)
Number of reading operations 和 Estimated number of matches 的注意事项
Number of reading operations 是与迭代器交互的次数。与其他值相比非常高的值是可能的警告标志。 NUMERIC 和 Child iterator 类型分为范围,Number of reading operations 将根据范围而变化。对于UNION,子迭代器中的读取操作之和应等于或大于子迭代器的读取操作。
Estimated number of matches 是文档集的大小。 Number of reading operations 应始终等于或小于 Estimated number of matches。
关于向量迭代器配置文件的注释 {#notes-onvector-iterator-profile}
对于向量查询,迭代器配置文件包括特定于向量搜索执行的附加信息。
矢量搜索模式
Vector search mode 字段指示用于 VECTOR 和 METRIC - VECTOR DISTANCE 迭代器类型的执行策略:
| 模式 | 说明 |
|---|---|
STANDARD_KNN |
没有过滤器的纯KNN向量搜索。 |
RANGE_QUERY |
基于范围的矢量搜索。与 VECTOR_RANGE 查询一起使用。 |
HYBRID_ADHOC_BF |
针对过滤查询的临时暴力破解。迭代通过过滤器的结果并即时计算距离。 |
HYBRID_BATCHES |
基于批量的过滤搜索。批量从索引中检索顶部向量并检查哪些向量通过了过滤器。 |
HYBRID_BATCHES_TO_ADHOC_BF |
动态模式切换。从基于批量的搜索开始,但如果批量迭代产生的结果不足,则切换到临时暴力搜索。 |
批量执行统计
对于使用批处理模式(HYBRID_BATCHES 或 HYBRID_BATCHES_TO_ADHOC_BF)的查询,还包括额外的批处理统计信息:
| 返回的字段名 | 定义 |
|---|---|
Batches number |
搜索期间执行的批量迭代总数。 |
Largest batch size |
执行期间使用的最大批量大小。批量大小可能会根据估计的匹配文档与总索引大小的比率动态变化。 |
Largest batch iteration (zero based) |
最大批次发生时的迭代次数(从0开始)。 |
结果处理器配置文件
结果处理器在Redis搜索中形成了强大的管道。它们分阶段工作,根据复杂的查询需求尽可能高效地收集、过滤、评分、排序和返回结果。每个处理器报告 Time 信息(表示处理器完成其操作所花费的总持续时间(以毫秒或 ms 为单位))和 Results processed 信息(表示查询期间调用处理器的次数)。
| 类型 | 定义 |
|---|---|
Metrics Applier |
Metrics Applier 处理器计算或聚合与搜索结果相关的特定指标。例如,这可能包括对矢量搜索结果应用距离或相似性度量,或者根据相关性或其他参数计算分数。 |
Index |
Index 处理器负责根据初始查询条件(例如全文术语、过滤器或数字范围)从索引中核心检索匹配文档。 |
Scorer |
Scorer 处理器根据查询指定的评分函数为每个文档分配相关性分数。该函数可能涉及术语频率、逆文档频率或其他加权指标等因素。 |
Sorter |
Sorter 处理器根据指定的排序标准排列查询结果。这可以是字段值(例如,按价格、日期或其他属性排序)或按评分阶段分配的分数。它在获取文档并对其进行评分后运行,确保结果按照查询的要求进行排序(例如,升序或降序)。 Scorer 结果将始终出现在 FT.SEARCH 配置文件中。 |
Loader |
Loader 处理器在对结果进行排序和过滤后检索文档内容。它确保只加载查询指定的字段,这提高了效率,特别是在处理只需要几个字段的大型文档时。 |
Threadsafe-Loader |
当查询在后台线程中运行时(与多线程部署相关),Threadsafe-Loader 处理器会安全地加载文档内容。它获取Redis全局锁(简称GIL)来访问文档数据。报告一个附加的 GIL-Time 字段,表示持有 GIL 并等待获取它所花费的时间(毫秒)。 |
Highlighter |
Highlighter 处理器用于突出显示搜索结果中的匹配术语。这对于全文搜索应用程序特别有用,因为相关术语经常在 UI 中强调。 |
Pager/Limiter |
Pager/Limiter 处理器负责通过将结果限制在特定范围(例如 LIMIT 0 10)来处理分页。它会缩减结果集以适合所需的分页窗口,从而确保在处理大型结果集时有效地使用内存。 |
Counter |
Counter 处理器统计匹配结果的总数。使用 LIMIT 0 0 运行查询时使用以仅返回计数。 |
Grouper |
Grouper 处理器按字段值对结果进行分组。在 FT.AGGREGATE 查询中与 GROUPBY 一起使用。 |
Projector |
Projector 处理器应用字段转换。在 FT.AGGREGATE 查询中与 APPLY 一起使用。 |
Network |
收集并合并分片结果。在集群模式下,作为 FT.AGGREGATE 的协调器结果处理器链中的根处理器出现。 |
协调员
此部分仅在多分片环境中运行时出现。
| 返回的字段名 | 定义 |
|---|---|
Total coordinator time |
从查询执行开始到所有分片完成查询执行所测量的时间。 (毫秒) |
Post-processing time |
生成 FT.PROFILE 输出(开销)所花费的时间(毫秒)。 |
示例
Collect performance information about a simple JSON index.
假设您有 (1) 一个由 10 个 JSON 文档组成的数据集,每个文档具有以下结构;
{
"pickup_zone": "POLYGON((-74.0610 40.7578, -73.9510 40.7578, -73.9510 40.6678, -74.0610 40.6678, -74.0610 40.7578))",
"store_location": "-74.0060,40.7128",
"brand": "Velorim",
"model": "Jigger",
"price": 270,
"description": "Small and powerful, the Jigger is the best ride for the smallest of tikes! This is the tiniest kids’ pedal bike on the market available without a coaster brake, the Jigger is the vehicle of choice for the rare tenacious little rider raring to go.",
"condition": "new"
}
以及(2)相应的索引:
FT.CREATE idx:bicycle ON JSON PREFIX 1 bicycle: SCORE 1.0 SCHEMA $.pickup_zone AS pickup_zone GEOSHAPE $.store_location AS store_location GEO $.brand AS brand TEXT WEIGHT 1.0 $.model AS model TEXT WEIGHT 1.0 $.description AS description TEXT WEIGHT 1.0 $.price AS price NUMERIC $.condition AS condition TAG SEPARATOR ,
下面是运行 FT.PROFILE 命令进行复合查询的示例。
127.0.0.1:6379> ft.profile idx:bicycle search query "@description:(kids | small) @condition:{new | used}"
1) 1) (integer) 3
2) "bicycle:0"
3) 1) "$"
2) "{\"pickup_zone\":\"POLYGON((-74.0610 40.7578, -73.9510 40.7578, -73.9510 40.6678, -74.0610 40.6678, -74.0610 40.7578))\",\"store_location\":\"-74.0060,40.7128\",\"brand\":\"Velorim\",\"model\":\"Jigger\",\"price\":270,\"description\":\"Small and powerful, the Jigger is the best ride for the smallest of tikes! This is the tiniest kids\xe2\x80\x99 pedal bike on the market available without a coaster brake, the Jigger is the vehicle of choice for the rare tenacious little rider raring to go.\",\"condition\":\"new\"}"
4) "bicycle:1"
5) 1) "$"
2) "{\"pickup_zone\":\"POLYGON((-118.2887 34.0972, -118.1987 34.0972, -118.1987 33.9872, -118.2887 33.9872, -118.2887 34.0972))\",\"store_location\":\"-118.2437,34.0522\",\"brand\":\"Bicyk\",\"model\":\"Hillcraft\",\"price\":1200,\"description\":\"Kids want to ride with as little weight as possible. Especially on an incline! They may be at the age when a 27.5\\\" wheel bike is just too clumsy coming off a 24\\\" bike. The Hillcraft 26 is just the solution they need!\",\"condition\":\"used\"}"
6) "bicycle:2"
7) 1) "$"
2) "{\"pickup_zone\":\"POLYGON((-87.6848 41.9331, -87.5748 41.9331, -87.5748 41.8231, -87.6848 41.8231, -87.6848 41.9331))\",\"store_location\":\"-87.6298,41.8781\",\"brand\":\"Nord\",\"model\":\"Chook air 5\",\"price\":815,\"description\":\"The Chook Air 5 gives kids aged six years and older a durable and uberlight mountain bike for their first experience on tracks and easy cruising through forests and fields. The lower top tube makes it easy to mount and dismount in any situation, giving your kids greater safety on the trails.\",\"condition\":\"used\"}"
2) 1) 1) Total profile time
2) "0"
2) 1) Parsing time
2) "0"
3) 1) Pipeline creation time
2) "0"
4) 1) Warning
5) 1) Iterators profile
2) 1) Type
2) INTERSECT
3) Time
4) "0"
5) Number of reading operations
6) (integer) 6
7) Child iterators
8) 1) Type
2) UNION
3) Query type
4) UNION
5) Time
6) "0"
7) Number of reading operations
8) (integer) 6
9) Child iterators
10) 1) Type
2) UNION
3) Query type
4) UNION
5) Time
6) "0"
7) Number of reading operations
8) (integer) 4
9) Child iterators
10) 1) Type
2) TEXT
3) Term
4) kids
5) Time
6) "0"
7) Number of reading operations
8) (integer) 4
9) Estimated number of matches
10) (integer) 4
11) 1) Type
2) TEXT
3) Term
4) +kid
5) Time
6) "0"
7) Number of reading operations
8) (integer) 4
9) Estimated number of matches
10) (integer) 4
11) 1) Type
2) TEXT
3) Term
4) small
5) Time
6) "0"
7) Number of reading operations
8) (integer) 2
9) Estimated number of matches
10) (integer) 2
9) 1) Type
2) UNION
3) Query type
4) TAG
5) Time
6) "0"
7) Number of reading operations
8) (integer) 6
9) Child iterators
10) 1) Type
2) TAG
3) Term
4) new
5) Time
6) "0"
7) Number of reading operations
8) (integer) 4
9) Estimated number of matches
10) (integer) 10
11) 1) Type
2) TAG
3) Term
4) used
5) Time
6) "0"
7) Number of reading operations
8) (integer) 4
9) Estimated number of matches
10) (integer) 8
6) 1) Result processors profile
2) 1) Type
2) Index
3) Time
4) "0"
5) Results processed
6) (integer) 3
3) 1) Type
2) Scorer
3) Time
4) "0"
5) Results processed
6) (integer) 3
4) 1) Type
2) Sorter
3) Time
4) "0"
5) Results processed
6) (integer) 3
5) 1) Type
2) Loader
3) Time
4) "0"
5) Results processed
6) (integer) 3
{{< / highlight >}}
</details>
<details>
<summary><b>Collect performance information about a JSON index that includes vector data.</b></summary>
For this example, you'll create a very simple vector database and index.
Index:
FT.CREATE vss_idx ON JSON PREFIX 1 vec: SCHEMA $.vector AS vector VECTOR FLAT 6 TYPE FLOAT32 DIM 4 DISTANCE_METRIC L2
Database:
JSON.SET vec:1 $ '{"vector":[1,1,1,1]}'
JSON.SET vec:2 $ '{"vector":[2,2,2,2]}'
JSON.SET vec:3 $ '{"vector":[3,3,3,3]}'
JSON.SET vec:4 $ '{"vector":[4,4,4,4]}'
Here's an example of running the `FT.PROFILE` command for a vector query.
{{< highlight bash >}}
127.0.0.1:6379> ft.profile vss_idx search query "*=>[KNN 3 @vector $query_vec]" PARAMS 2 query_vec "\x00\x00\x00@\x00\x00\x00@\x00\x00@@\x00\x00@@" SORTBY __vector_score DIALECT 2
1) 1) (integer) 3
2) "vec:2"
3) 1) "__vector_score"
2) "2"
3) "$"
4) "{\"vector\":[2,2,2,2]}"
4) "vec:3"
5) 1) "__vector_score"
2) "2"
3) "$"
4) "{\"vector\":[3,3,3,3]}"
6) "vec:1"
7) 1) "__vector_score"
2) "10"
3) "$"
4) "{\"vector\":[1,1,1,1]}"
2) 1) 1) Total profile time
2) "0"
2) 1) Parsing time
2) "0"
3) 1) Pipeline creation time
2) "0"
4) 1) Warning
5) 1) Iterators profile
2) 1) Type
2) VECTOR
3) Time
4) "0"
5) Number of reading operations
6) (integer) 3
6) 1) Result processors profile
2) 1) Type
2) Index
3) Time
4) "0"
5) Results processed
6) (integer) 3
3) 1) Type
2) Metrics Applier
3) Time
4) "0"
5) Results processed
6) (integer) 3
4) 1) Type
2) Sorter
3) Time
4) "0"
5) Results processed
6) (integer) 3
5) 1) Type
2) Loader
3) Time
4) "0"
5) Results processed
6) (integer) 3
Redis Software 与 Redis Cloud 兼容性
| Redis 软件 |
Redis软件 Flex |
Redis Cloud 灵活且每年 |
Redis Cloud 免费和固定 |
说明 |
|---|---|---|---|---|
| ✅ 支持 | ✅ 支持 | ✅ 支持 | ✅ 支持 |
返回值
RESP2
以下之一: * 数组 具有两个元素:搜索结果和分析信息。 * 简单错误回复 在这些情况下:没有这样的索引,查询中有语法错误。
RESP3
以下之一: * 地图 有两个键:Results 包含搜索结果,Profile 包含分析信息。 * 简单错误回复 在这些情况下:没有这样的索引,查询中有语法错误。
参见
FT.SEARCH | FT.HYBRID | FT.AGGREGATE
相关主题
资料来源:Redis 官方 FT.PROFILE 文档;中文内容参考 Redis 文档许可。