语义搜索 (SQL Server)Semantic Search (SQL Server)

适用对象:是SQL Server 否Azure SQL 数据库 否Azure Synapse Analytics (SQL DW) 否并行数据仓库APPLIES TO: yesSQL Server noAzure SQL Database noAzure Synapse Analytics (SQL DW) noParallel Data Warehouse

统计语义搜索通过提取统计上相关的“关键短语” SQL ServerSQL Server并对其进行索引,提供对中存储的非结构化文档的更深层次剖析。Statistical Semantic Search provides deep insight into unstructured documents stored in SQL ServerSQL Server databases by extracting and indexing statistically relevant key phrases. 然后,它使用这些关键短语标识“相似或相关文档” 并对其进行索引。Then it uses these key phrases to identify and index documents that are similar or related.

使用语义搜索可以做什么?What can you do with Semantic Search?

语义搜索以 SQL ServerSQL Server中现有的全文搜索功能为基础,但允许超出关键字搜索范畴的新方案。Semantic search builds upon the existing full-text search feature in SQL ServerSQL Server, but enables new scenarios that extend beyond keyword searches. 全文搜索允许你查询文档中的“词” ,语义搜索则允许你查询文档的“含义” 。While full-text search lets you query the words in a document, semantic search lets you query the meaning of the document. 现有的可能解决方案包括自动标记提取、相关内容发现以及相似内容中层次结构导航。Solutions that are now possible include automatic tag extraction, related content discovery, and hierarchical navigation across similar content. 例如,您可以查询关键短语的索引来建立一个组织或文档集的分类索引。For example, you can query the index of key phrases to build the taxonomy for an organization, or for a corpus of documents. 或者,您可以查询文档相似性索引来标识匹配某一工作描述的简历。Or, you can query the document similarity index to identify resumes that match a job description.

下面的示例演示了语义搜索的功能。The following examples demonstrate the capabilities of Semantic Search. 同时,这些示例还展示了你用来查询语义索引和以结构化数据形式检索结果的三个 Transact-SQL 行集函数。At the same time these examples demonstrate the three Transact-SQL rowset functions that you use to query the semantic indexes and retrieve the results as structured data.

在文档中查找关键短语Find the key phrases in a document

下面的查询获取在示例文档中已标识的关键短语。The following query gets the key phrases that were identified in the sample document. 该查询按照对每个关键短语的统计重要性进行排名的分数以降序方式展示结果。It presents the results in descending order by the score that ranks the statistical significance of each key phrase.

此查询调用 semantickeyphrasetable 函数。This query calls the semantickeyphrasetable function.

SET @Title = 'Sample Document.docx'  
  
SELECT @DocID = DocumentID  
    FROM Documents  
    WHERE DocumentTitle = @Title  
  
SELECT @Title AS Title, keyphrase, score  
    FROM SEMANTICKEYPHRASETABLE(Documents, *, @DocID)  
    ORDER BY score DESC  
  

Find similar or related documentsFind similar or related documents

以下查询获取已标识为与示例文档相似或相关的文档。The following query gets the documents that were identified as similar or related to the sample document. 该查询按照对这两个文档的相似性进行排名的分数以降序方式展示结果。It presents the results in descending order by the score that ranks the similarity of the two documents.

此查询调用 semanticsimilaritytable 函数。This query calls the semanticsimilaritytable function.

SET @Title = 'Sample Document.docx'  
  
SELECT @DocID = DocumentID  
    FROM Documents  
    WHERE DocumentTitle = @Title  
  
SELECT @Title AS SourceTitle, DocumentTitle AS MatchedTitle,  
        DocumentID, score  
    FROM SEMANTICSIMILARITYTABLE(Documents, *, @DocID)  
    INNER JOIN Documents ON DocumentID = matched_document_key  
    ORDER BY score DESC  
  

查找使文档相似或相关的关键短语Find the key phrases that make documents similar or related

以下查询获取使两个示例文档彼此相似或相关的关键短语。The following query gets the key phrases that make the two sample documents similar or related to one another. 该查询按照对每个关键短语的权重进行排名的分数以降序方式展示结果。It presents the results in descending order by the score that ranks the weight of each key phrase.

此查询调用 semanticsimilaritydetailstable 函数。This query calls the semanticsimilaritydetailstable function.

SET @SourceTitle = 'first.docx'  
SET @MatchedTitle = 'second.docx'  
  
SELECT @SourceDocID = DocumentID FROM Documents WHERE DocumentTitle = @SourceTitle  
SELECT @MatchedDocID = DocumentID FROM Documents WHERE DocumentTitle = @MatchedTitle  
  
SELECT @SourceTitle AS SourceTitle, @MatchedTitle AS MatchedTitle, keyphrase, score  
    FROM semanticsimilaritydetailstable(Documents, DocumentContent,  
        @SourceDocID, DocumentContent, @MatchedDocID)  
    ORDER BY score DESC  
  

在 SQL Server 中存储文档Store your documents in SQL Server

在您可以使用语义搜索对文档建立索引之前,必须在 SQL ServerSQL Server 数据库中存储文档。Before you can index documents with Semantic Search, you have to store the documents in a SQL ServerSQL Server database.

SQL Server 中的 FileTable 功能使非结构化的文件和文档能够很好地通过关系数据库处理。The FileTable feature in SQL Server makes unstructured files and documents first-class citizens of the relational database. 这样,数据库开发人员在 Transact-SQL 基于集的操作中可以将文档与结构化数据一起处理。As a result, database developers can manipulate documents together with structured data in Transact-SQL set-based operations.

有关 FileTable 功能的详细信息,请参阅 FileTables (SQL Server)For more info about the FileTable feature, see FileTables (SQL Server). 有关 FILESTREAM 功能(这是用于在数据库中存储文档的另一个选项)的信息,请参阅 FILESTREAM (SQL Server)For info about the FILESTREAM feature, which is another option for storing documents in the database, see FILESTREAM (SQL Server).

Related tasksRelated tasks

安装和配置语义搜索Install and Configure Semantic Search
说明统计语义搜索的必备组件以及如何安装或检查它们。Describes the prerequisites for statistical semantic search and how to install or check them.

对表和列启用语义搜索Enable Semantic Search on Tables and Columns
介绍如何启用或禁用包含文档或文本的选定列上的统计语义索引。Describes how to enable or disable statistical semantic indexing on selected columns that contain documents or text.

使用语义搜索查找文档中的关键短语Find Key Phrases in Documents with Semantic Search
介绍如何在为统计语义索引配置的文档或文本列中查找关键短语。Describes how to find the key phrases in documents or text columns that are configured for statistical semantic indexing.

使用语义搜索来查找相似和相关文档Find Similar and Related Documents with Semantic Search
说明在为统计语义索引配置的列上如何查找相似或相关的文档或文本值,以及如何查找其相似或相关程度的信息。Describes how to find similar or related documents or text values, and information about how they are similar or related, in columns that are configured for statistical semantic indexing.

管理和监视语义搜索Manage and Monitor Semantic Search
说明语义索引编制的进度以及与监视和管理索引有关的任务。Describes the process of semantic indexing and the tasks related to monitoring and managing the indexes.

Related contentRelated content

语义搜索 DDL、函数、存储过程和视图Semantic Search DDL, Functions, Stored Procedures, and Views
列出用于支持统计语义搜索的新增或更改的 Transact-SQL 语句和 SQL Server 数据库对象。Lists the Transact-SQL statements and the SQL Server database objects added or changed to support statistical semantic search.