Query the Cortex Search service with Snowflake Connector for SharePoint

Note

The Snowflake Connector for SharePoint is subject to the Connector Terms.

Important

Thank you for your interest in the Snowflake Connector for SharePoint. We’re now focused on a next-generation solution that will offer a significantly improved experience; therefore, moving this connector to the general availability status is currently not on our product roadmap. You may continue to use this connector as a preview feature, but please note that support for future bug fixes and improvements is not guaranteed. The new solution is available as Openflow Connector for SharePoint and includes better performance, customizability, and enhanced deployment options.

You can use the Cortex Search service to build chat and search applications to chat with or query your documents in SharePoint.

After you install and configure the Snowflake Connector for SharePoint and it begins ingesting content from Sharepoint, you can query the Cortex Search service. For more information about using Cortex Search, see Query a Cortex Search service.

筛选器响应

To restrict responses from the Cortex Search service to documents that a specific user has access to in SharePoint, you can specify a filter containing the user ID or email address of the user when you query Cortex Search. For example, filter.@contains.user_ids or filter.@contains.user_emails. The name of the Cortex Search service created by the connector is search_service in the schema Cortex.

在 SQL 工作表中运行以下 SQL 代码,利用从 SharePoint 站点引入的文件查询 Cortex Search 服务。

替换以下内容:

  • application_instance_name: Name of your database and connector application instance.
  • user_emailID: Email ID of the user who you want to filter the responses for.
  • your_question: The question that you want to get responses for.
  • number_of_results: Maximum number of results to return in the response. The maximum value is 1000 and the default value is 10.
SELECT PARSE_JSON(
  SNOWFLAKE.CORTEX.SEARCH_PREVIEW(
    '<application_instance_name>.cortex.search_service',
      '{
        "query": "<your_question>",
         "columns": ["chunk", "web_url"],
         "filter": {"@contains": {"user_emails": "<user_emailID>"} },
         "limit": <number_of_results>
       }'
   )
)['results'] AS results

Here’s a complete list of values that you can enter for columns:

Column nameTypeDescription
full_nameStringA full path to the file from the Sharepoint site documents root. Example: folder_1/folder_2/file_name.pdf.
web_urlStringA URL that displays an original Sharepoint file in a browser.
last_modified_date_timeStringDate and time when the item was most recently modified.
chunkStringA piece of text from the document that matched the Cortex Search query.
user_idsArrayAn array of Microsoft 365 user IDs that have access to the document. It also includes user IDs from all the Microsoft 365 groups that are assigned to the document. To find a specific user ID, see Get a user (https://learn.microsoft.com/en-us/graph/api/user-get?view=graph-rest-1.0&tabs=http).
user_emailsArrayAn array of Microsoft 365 user email IDs that have access to the document. It also includes user email IDs from all the Microsoft 365 groups that are assigned to the document.

示例:向 AI 助手查询人力资源 (HR) 信息

您可以使用 Cortex Search 查询 AI 助手,为员工聊天提供最新版本的 HR 信息,如入职、行为规范、团队流程和组织政策等。使用响应筛选器,您还可以允许 HR 团队成员查询员工合同,同时遵守 SharePoint 中配置的访问控制。

Run the following code in a Python worksheet to query the Cortex Search service with files ingested from SharePoint. Ensure that you add the snowflake.core package to your database.

替换以下内容:

  • application_instance_name: Name of your database and connector application instance.
  • user_emailID: Email ID of the user who you want to filter the responses for.
import snowflake.snowpark as snowpark
from snowflake.snowpark import Session
from snowflake.core import Root

def main(session: snowpark.Session):

   root = Root(session)

   # fetch service
   my_service = (root
     .databases["<application_instance_name>"]
     .schemas["cortex"]
     .cortex_search_services["search_service"]
   )

   # query service
   resp = my_service.search(
     query="What is my vacation carry over policy?",
     columns = ["chunk", "web_url"],
     filter = {"@contains": {"user_emails": "<user_emailID>"} },
     limit=1
   )
   return (resp.to_json())

后续步骤

Manage the Snowflake Connector for SharePoint.