CreateSemanticSearchIndex[source]
从 source 中的数据创建搜索索引.
CreateSemanticSearchIndex[{source1,…}]
用一系列资源创建搜索索引 sourcei.
CreateSemanticSearchIndex[{source1val1,…}]
将资源 sourcei 与值 vali 关联在一起.
CreateSemanticSearchIndex[data,"name"]
为搜索索引指定名称.
CreateSemanticSearchIndex
CreateSemanticSearchIndex[source]
从 source 中的数据创建搜索索引.
CreateSemanticSearchIndex[{source1,…}]
用一系列资源创建搜索索引 sourcei.
CreateSemanticSearchIndex[{source1val1,…}]
将资源 sourcei 与值 vali 关联在一起.
CreateSemanticSearchIndex[data,"name"]
为搜索索引指定名称.
更多信息和选项
- CreateSemanticSearchIndex 用于从文本中提取可用来对内容进行语义搜索的特征.
- source 可取的值有:
-
"string" 纯字符串 File["path"] 单个文件 URL["url"] "url" 的文本表示 CloudObject[…] 云对象 LocalObject[…] 本地对象 ContentObject[…] 内容对象 {source1,source2,…} 资源列表 - 可为资源添加注释. 来自给定资源的每个数据块都将具有相同的注释.
- 指定注释的可能的方法包括:
-
{soure1val1,…} 资源和关联的值组成的列表 {source1,…}{val1,…} 资源和值组成的规则 - 可接受的 vali 的形式包括:
-
"string" 字符串标签 <|"tag1"v1,…|> 标签和元数据值组成的关联 - CreateSemanticSearchIndex 支持以下选项:
-
DistanceFunction EuclideanDistance 使用的距离函数 FeatureExtractor "MiniLM" 如何从文本片段中提取特征 GeneratedAssetLocation $GeneratedAssetLocation 索引的位置 Method Automatic 方法的详细信息 OverwriteTarget Automatic 是否覆盖现有位置 ProgressReporting $ProgressReporting 是否报告计算进度 WorkingPrecision "Real32" 浮点计算的精度 - DistanceFunction 可取的值包括 EuclideanDistance、SquaredEuclideanDistance、CosineDistance、JaccardDissimilarity 和 HammingDistance.
- FeatureExtractor 可取的值包括:
-
"MiniLM" 基于 SentenceBERT 的本地模型 LLMConfiguration 基于 LLM 的语句嵌入 f 自定义的提取函数 - 自定义的提取函数 f 必须在字符串列表上进行操作并生成相同长度的向量列表.
- 通过 Method<|opt1val1|> 给出选项. opti 可取的值有:
-
"ContextPadding" 
片段之间的最小重叠 "MaximumItemLength" 
文本片段的最小长度 "MinimumItemLength" 
文本片段的最大长度 "SplitPattern" Automatic 在哪里分割长字符串 - 设为自动的 "SplitPattern" 尝试将资源文本拆分为段落、换行符和单词,创建长度位于 "MinimumItemLength" 和 "MaximumItemLength" 之间的片段.
- WorkingPrecision 可能的设置包括:
-
"Integer8" 从 -128 到 127 的有符号 8 位整数 "Real32" 单精度实数 (32-bit) "Real64" 双精度实数 (64-bit)
范例
打开所有单元 关闭所有单元基本范例 (2)
创建一个新的 SemanticSearchIndex:
index = CreateSemanticSearchIndex[ResourceData["Alice in Wonderland"], "Alice"]Short /@ SemanticSearch[index, "talking insect", MaxItems -> 4]index = CreateSemanticSearchIndex[{ResourceData["Alice in Wonderland"] -> "Alice", ResourceData["Death in Venice"] -> "Venice"}]SemanticSearch[index, "insects"]范围 (6)
数据源 (4)
CreateSemanticSearchIndex["Cats, with their mysterious charm and playful antics, effortlessly capture our hearts, prancing gracefully through sunbeams, curling up in cozy spots, and purring softly, reminding us of the joy they bring."]CreateSemanticSearchIndex[File["ExampleData/USConstitution.txt"]]CreateSemanticSearchIndex[URL["http://www.wolfram.com"]]CreateSemanticSearchIndex[ResourceData["Alice in Wonderland"], "Alice"]注释 (2)
index = CreateSemanticSearchIndex[{ResourceData["Friends, Romans, Countrymen"] -> "Caesar", ResourceData["JFK Inaugural Address"] -> "JFK"}]index["Label"]SemanticSearch[index, "honour"]CreateSemanticSearchIndex[{ResourceData["Alice in Wonderland"] -> <|"Author" -> "Lewis Carroll", "Date" -> 1865 |>, ResourceData["Friends, Romans, Countrymen"] -> <|"Author" -> "William Shakespeare", "Date" -> 1609|>}]用单独的 Association 指定注释:
CreateSemanticSearchIndex[{ResourceData["Alice in Wonderland"], ResourceData["Friends, Romans, Countrymen"]} -> {<|"Author" -> "Lewis Carroll", "Date" -> 1865|>, <|"Author" -> "William Shakespeare", "Date" -> 1609|>}]选项 (10)
DistanceFunction (1)
CreateSemanticSearchIndex[{"beautiful", "mysterious", "vibrant", "ancient"}, DistanceFunction -> CosineDistance]默认情况下,使用 EuclideanDistance:
CreateSemanticSearchIndex[{"beautiful", "mysterious", "vibrant", "ancient"}]["Database"]["DistanceFunction"]FeatureExtractor (1)
GeneratedAssetLocation (3)
index = CreateSemanticSearchIndex[ResourceData["Declaration of Independence"], GeneratedAssetLocation -> "CloudObject"]index["Location"]CreateSemanticSearchIndex[RandomWord[10]]["Location"]file = File[FileNameJoin[{$TemporaryDirectory, "testfile"}]]CreateSemanticSearchIndex[RandomWord[10], GeneratedAssetLocation -> file]%["Location"]SemanticSearchIndex[File["/private/var/folders/05/v_ct9frn7zv4vy6f2q18y2r80000gn/T/testfile"]]Method (2)
text = "abacus: a calculator that performs arithmetic functions by manually sliding counters on rods or in groovesa tablet placed horizontally on top of the capital of a column as an aid in supporting the architrave
abaft: at or near or toward the stern of a ship or tail of an airplanepreposition
abalone: any of various large edible marine gastropods of the genus Haliotis having an ear-shaped shell with pearly interior
abandoned: forsaken by owner or inhabitants free from constraint";CreateSemanticSearchIndex[text]CreateSemanticSearchIndex[text, Method -> {"MinimumItemLength" -> 1, "MaximumItemLength" -> 64}]definitions = Map[StringJoin[#, ": ", WordDefinition[#]]&, RandomWord[50]];
Short[definitions]text = StringRiffle[definitions, " !!! "];First@CreateSemanticSearchIndex[text]["Items"]First@CreateSemanticSearchIndex[text, Method -> <|"SplitPattern" -> StringExpression["!!!"], "MinimumItemLength" -> 4|>]["Items"]OverwriteTarget (2)
CreateSemanticSearchIndex[StringRiffle[RandomWord[10]], "myDB"]如果采用默认的 OverwriteTargetAutomatic,将生成一个新的索引名称以避免冲突:
CreateSemanticSearchIndex[StringRiffle[RandomWord[10]], "myDB"]如果想强制覆盖,可使用 OverwriteTargetTrue:
CreateSemanticSearchIndex[StringRiffle[RandomWord[10]], "myDB", OverwriteTarget -> True]用 OverwriteTargetFalse 进行更严格的检查:
CreateSemanticSearchIndex[RandomWord[10], "myDB", OverwriteTarget -> False]OverwriteTargetFalse 还将防止在不同位置重复使用相同的索引名称:
CreateSemanticSearchIndex[RandomWord[10], "myDB", GeneratedAssetLocation -> File["myDBfile"], OverwriteTarget -> False]CreateFile@File["myIndexfile"]CreateSemanticSearchIndex[RandomWord[10], GeneratedAssetLocation -> File["myIndexfile"]]用 OverwriteTargetTrue 覆盖现有文件:
CreateSemanticSearchIndex[RandomWord[10], GeneratedAssetLocation -> File["myIndexfile"], OverwriteTarget -> True]应用 (2)
data = Map[StringRiffle[WordDefinition[#]] -> #&, WordList[]];CreateSemanticSearchIndex[data, "definitions"]SemanticSearch["definitions", "small land insect"]index = CreateSemanticSearchIndex[ResourceData["Shakespeare's Sonnets"]]SemanticSearch[index, "a day in the summer", MaxItems -> 1]属性和关系 (1)
text = "This is a sentence."
semanticEmbeddings = Normal@CreateSemanticSearchIndex[text]["Embeddings"];
Short[semanticEmbeddings]FeatureExtract 可使用指定的 "SentenceVector" 提取器来创建类似的嵌入:
featureEmbeddings = FeatureExtract[{text}, "SentenceVector"];
Short@featureEmbeddings可能存在的问题 (2)
CreateSemanticSearchIndex["https://www.wolfram.com"]["Items"]要访问该链接,请使用 URL 封装:
CreateSemanticSearchIndex[URL["https://www.wolfram.com"]]["Items"]//First//Short用 File 导入文件的内容:
FileCreateSemanticSearchIndex[File["ExampleData/USConstitution.txt"]]["Items"]//First//Shorttext = "abacus: a calculator that performs arithmetic functions by manually sliding counters on rods or in groovesa tablet placed horizontally on top of the capital of a column as an aid in supporting the architrave
abaft: at or near or toward the stern of a ship or tail of an airplanepreposition
abalone: any of various large edible marine gastropods of the genus Haliotis having an ear-shaped shell with pearly interior
abandoned: forsaken by owner or inhabitants free from constraint";index = CreateSemanticSearchIndex[text, Method -> {"MinimumItemLength" -> 1}]index = CreateSemanticSearchIndex[text, Method -> {"MinimumItemLength" -> 1, "MaximumItemLength" -> 64}]相关指南
文本
Wolfram Research (2024),CreateSemanticSearchIndex,Wolfram 语言函数,https://reference.wolfram.com/language/ref/CreateSemanticSearchIndex.html (更新于 2025 年).
CMS
Wolfram 语言. 2024. "CreateSemanticSearchIndex." Wolfram 语言与系统参考资料中心. Wolfram Research. 最新版本 2025. https://reference.wolfram.com/language/ref/CreateSemanticSearchIndex.html.
APA
Wolfram 语言. (2024). CreateSemanticSearchIndex. Wolfram 语言与系统参考资料中心. 追溯自 https://reference.wolfram.com/language/ref/CreateSemanticSearchIndex.html 年
BibTeX
@misc{reference.wolfram_2026_createsemanticsearchindex, author="Wolfram Research", title="{CreateSemanticSearchIndex}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/CreateSemanticSearchIndex.html}", note=[Accessed: 08-September-2026]}
BibLaTeX
@online{reference.wolfram_2026_createsemanticsearchindex, organization={Wolfram Research}, title={CreateSemanticSearchIndex}, year={2025}, url={https://reference.wolfram.com/language/ref/CreateSemanticSearchIndex.html}, note=[Accessed: 08-September-2026]}