> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-postgresql-tls-support.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# vector_search_* 会话设置

> ClickHouse 在 vector_search_* 生成组中的会话设置。

export const VersionHistory = ({rows = []}) => {
  if (rows.length === 0) {
    return null;
  }
  const headers = ["版本", "默认值", "注释"];
  const border = "1px solid rgba(128, 128, 128, 0.3)";
  const cell = {
    border,
    padding: "0.25rem 0.5rem",
    textAlign: "start",
    verticalAlign: "top"
  };
  return <details className="not-prose" style={{
    border,
    borderRadius: "0.5rem",
    margin: "0.5rem 0",
    padding: "0.5rem 0.75rem",
    fontSize: "0.8125rem",
    lineHeight: "1.125rem"
  }}>
      <summary style={{
    cursor: "pointer",
    fontWeight: 600,
    opacity: 0.72
  }}>
        版本历史
      </summary>
      <table style={{
    borderCollapse: "collapse",
    width: "100%",
    margin: "0.5rem 0 0"
  }}>
        <thead>
          <tr>
            {headers.map(header => <th key={header} style={{
    ...cell,
    fontWeight: 600,
    opacity: 0.72
  }}>
                {header}
              </th>)}
          </tr>
        </thead>
        <tbody>
          {rows.map((row, row_index) => <tr key={row.id ?? row_index}>
              {(row.items ?? []).map((item, item_index) => <td key={item_index} style={{
    ...cell,
    overflowWrap: "anywhere"
  }}>
                  {item?.label}
                </td>)}
            </tr>)}
        </tbody>
      </table>
    </details>;
};

export const SettingsInfoBlock = ({type, default_value, changeable_without_restart}) => {
  return <div className="not-prose" style={{
    display: "flex",
    flexWrap: "wrap",
    alignItems: "baseline",
    columnGap: "0.5rem",
    rowGap: "0.125rem",
    margin: "0.375rem 0",
    fontSize: "0.8125rem",
    lineHeight: "1.125rem"
  }}>
      <div style={{
    fontWeight: 600,
    opacity: 0.72
  }}>类型</div>
      <div style={{
    overflowWrap: "anywhere"
  }}>{type}</div>
      <div style={{
    fontWeight: 600,
    opacity: 0.72,
    marginInlineStart: "0.5rem"
  }}>默认值</div>
      <div style={{
    overflowWrap: "anywhere"
  }}>{default_value}</div>
      {changeable_without_restart && <div style={{
    fontWeight: 600,
    opacity: 0.72,
    marginInlineStart: "0.5rem"
  }}>
          无需重启即可更改
        </div>}
      {changeable_without_restart && <div style={{
    overflowWrap: "anywhere"
  }}>
          {changeable_without_restart}
        </div>}
    </div>;
};

这些设置可在 [system.settings](/zh/reference/system-tables/settings) 中查看，并由 [源文件](https://github.com/ClickHouse/ClickHouse/blob/master/src/Core/Settings.cpp) 自动生成。

<div id="vector_search_filter_strategy">
  ## vector\_search\_filter\_strategy
</div>

<SettingsInfoBlock type="VectorSearchFilterStrategy" default_value="auto" />

如果向量搜索查询带有 WHERE 子句，此设置决定是先评估该子句 (前过滤) ，还是先检查向量相似度索引 (后过滤) 。可能的值：

* 'auto' - 后过滤 (确切语义今后可能会发生变化) 。
* 'postfilter' - 先使用向量相似度索引识别最近邻，然后再应用其他过滤条件
* 'prefilter' - 先评估其他过滤条件，再执行穷举搜索以识别邻居。

<div id="vector_search_index_fetch_multiplier">
  ## vector\_search\_index\_fetch\_multiplier
</div>

**别名**: `vector_search_postfilter_multiplier`

<SettingsInfoBlock type="Float" default_value="1" />

将从向量相似度索引中拉取的最近邻数量乘以此数值。仅在使用其他谓词进行后过滤时，或在设置 `vector_search_with_rescoring = 1` 时生效。有效范围：\[1.0, 1000.0]。超出此范围的值会被拒绝。

<div id="vector_search_use_quantized_codes">
  ## vector\_search\_use\_quantized\_codes
</div>

<SettingsInfoBlock type="Bool" default_value="0" />

启用对使用 `Quantized` 压缩的列执行无索引 (暴力扫描) 的两阶段近似向量搜索。启用后，对使用 `Quantized(...)` codec 编码的列执行 `ORDER BY L2Distance|cosineDistance(vec, reference) LIMIT k` 时，将会

1. 扫描并过滤量化后的向量 (此步骤会产生 `k * vector_search_index_fetch_multiplier` 个结果) ，以及
2. 使用原始全精度向量对找到的向量重新评分。

<div id="vector_search_with_rescoring">
  ## vector\_search\_with\_rescoring
</div>

<SettingsInfoBlock type="Bool" default_value="0" />

是否让 ClickHouse 对使用向量相似度索引的查询执行 rescoring。
不使用 rescoring 时，向量相似度索引会直接返回包含最佳匹配的行。
使用 rescoring 时，向量相似度索引会拉取候选行，而 ClickHouse 会在常规 SQL 管道中
基于原始全精度向量计算这些行的精确距离。
在可能的情况下，ClickHouse 会在最终距离计算前将扫描范围限制为候选行。
如果需要更多候选行以获得更好的召回率，请增大 `vector_search_index_fetch_multiplier`，尤其是在
使用额外过滤器或量化向量索引时。
注意：在不使用 rescoring 且启用了并行副本的情况下运行查询时，可能会回退到 rescoring。
