Skip to content

Azcognitive search

AzCognitiveSearchReader #

Bases: BaseReader

通用的 Azure Cognitive Search 索引读取器。

Parameters:

Name Type Description Default
service_name str

Azure Cognitive Search 服务的名称。

required
search_key str

直接提供 Azure 搜索访问密钥。

required
index str

索引名称

required
Source code in llama_index/readers/azcognitive_search/base.py
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
class AzCognitiveSearchReader(BaseReader):
    """通用的 Azure Cognitive Search 索引读取器。

    Args:
        service_name (str): Azure Cognitive Search 服务的名称。
        search_key (str): 直接提供 Azure 搜索访问密钥。
        index (str): 索引名称

"""

    def __init__(self, service_name: str, searck_key: str, index: str) -> None:
        """使用搜索密钥初始化Azure认知搜索服务。"""
        import logging

        logger = logging.getLogger("azure.core.pipeline.policies.http_logging_policy")
        logger.setLevel(logging.WARNING)

        azure_credential = AzureKeyCredential(searck_key)

        self.search_client = SearchClient(
            endpoint=f"https://{service_name}.search.windows.net",
            index_name=index,
            credential=azure_credential,
        )

    def load_data(
        self, query: str, content_field: str, filter: Optional[str] = None
    ) -> List[Document]:
        """从Azure认知搜索索引中读取数据。

Args:
    query (str): Azure搜索索引中的搜索词
    content_field (str): 文档内容的字段名。
    filter (str): 过滤表达式。例如:'sourcepage eq 'employee_handbook-3.pdf' and sourcefile eq 'employee_handbook.pdf''

Returns:
    List[Document]: 文档列表。
"""
        search_result = self.search_client.search(query, filter=filter)

        return [
            Document(
                text=result[content_field],
                extra_info={"id": result["id"], "score": result["@search.score"]},
            )
            for result in search_result
        ]

load_data #

load_data(
    query: str,
    content_field: str,
    filter: Optional[str] = None,
) -> List[Document]

从Azure认知搜索索引中读取数据。

Parameters:

Name Type Description Default
query str

Azure搜索索引中的搜索词

required
content_field str

文档内容的字段名。

required
filter str

过滤表达式。例如:'sourcepage eq 'employee_handbook-3.pdf' and sourcefile eq 'employee_handbook.pdf''

None

Returns:

Type Description
List[Document]

List[Document]: 文档列表。

Source code in llama_index/readers/azcognitive_search/base.py
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
    def load_data(
        self, query: str, content_field: str, filter: Optional[str] = None
    ) -> List[Document]:
        """从Azure认知搜索索引中读取数据。

Args:
    query (str): Azure搜索索引中的搜索词
    content_field (str): 文档内容的字段名。
    filter (str): 过滤表达式。例如:'sourcepage eq 'employee_handbook-3.pdf' and sourcefile eq 'employee_handbook.pdf''

Returns:
    List[Document]: 文档列表。
"""
        search_result = self.search_client.search(query, filter=filter)

        return [
            Document(
                text=result[content_field],
                extra_info={"id": result["id"], "score": result["@search.score"]},
            )
            for result in search_result
        ]