Tool

Connect to Azure Cognitive Search for Data Retrieval

Load documents from an Azure Cognitive Search index into LlamaIndex with query filtering.

Works with azure cognitive searchllama indexlangchain

71
Spark score
out of 100
Updated 2 days ago
Version 0.14.23
Models

Add to Favorites

Why it matters

Integrate your applications with Azure Cognitive Search to efficiently retrieve and utilize data from your indexes. This asset enables seamless data loading for further processing or analysis within AI frameworks.

Outcomes

What it gets done

01

Load documents from a specified Azure Cognitive Search index.

02

Query the search index using custom search terms and filters.

03

Extract relevant content fields from search results.

04

Integrate retrieved data into LlamaIndex or Langchain applications.

Install

Add it to your toolbox

Run in your project directory:

curl -fsSL https://spark.entire.vc/get/li-reader-readers-azcognitive-search | bash

Overview

Azure Cognitive Search Loader

A LlamaIndex reader that loads documents from an Azure Cognitive Search index via a filtered query, composable with LangChain agents. Use when you already index content in Azure Cognitive Search and want a query-filtered subset loaded for retrieval.

What it does

The Azure Cognitive Search Loader returns a set of texts corresponding to documents retrieved from a specific index of Azure Cognitive Search. The user initializes the loader with credentials - a service name and key - and the target index name.

AzCognitiveSearchReader is initialized with the Azure Cognitive Search service name, key, and index name. load_data then takes a query search term, a content_field naming which indexed field holds the document content, and an filter using Azure Search's own filter syntax to narrow results further.

When to use - and when NOT to

Use it when you already have data indexed in Azure Cognitive Search and want a specific, query-filtered subset of it loaded into LlamaIndex. It also composes with LangChain: the source's own example builds a LlamaIndex VectorStoreIndex from the loaded documents, wraps a query over that index as a LangChain Tool, and drives it through a conversational LangChain agent with memory - useful when a broader LangChain-based application needs Azure Search-backed answers grounded in a specific index. Do not use it as a way to write to or manage an Azure Cognitive Search index; it is a read-only loader built around a search query.

Capabilities

load_data runs a query against a named Azure Cognitive Search index, filtered by Azure Search's own filter syntax, and returns matching documents built from a specified content field.

How to install

pip install llama-index-readers-azcognitive-search

Requires an Azure Cognitive Search service name, key, and target index name.

Who it's for

Developers who already index content in Azure Cognitive Search and want a specific, query-filtered subset loaded into LlamaIndex or a LangChain agent for retrieval or question-answering.

Source README

Azure Cognitive Search Loader

pip install llama-index-readers-azcognitive-search

The AzCognitiveSearchReader Loader returns a set of texts corresponding to documents retrieved from specific index of Azure Cognitive Search.
The user initializes the loader with credentials (service name and key) and the index name.

Usage

Here's an example usage of the AzCognitiveSearchReader.

from llama_index.readers.azcognitive_search import AzCognitiveSearchReader

reader = AzCognitiveSearchReader(
    "<Azure_Cognitive_Search_NAME>",
    "<Azure_Cognitive_Search_KEY>",
    "<Index_name>",
)


query_sample = ""
documents = reader.load_data(
    query="<search_term>",
    content_field="<content_field_name>",
    filter="<azure_search_filter>",
)

Usage in combination with langchain

from llama_index.core import VectorStoreIndex, download_loader
from langchain.chains.conversation.memory import ConversationBufferMemory
from langchain.agents import Tool, AgentExecutor, load_tools, initialize_agent

from llama_index.readers.azcognitive_search import AzCognitiveSearchReader

az_loader = AzCognitiveSearchReader(
    COGNITIVE_SEARCH_SERVICE_NAME, COGNITIVE_SEARCH_KEY, INDEX_NAME
)

documents = az_loader.load_data(query, field_name)

index = VectorStoreIndex.from_documents(
    documents, service_context=service_context
)

tools = [
    Tool(
        name="Azure cognitive search index",
        func=lambda q: index.query(q),
        description=f"Useful when you want answer questions about the text on azure cognitive search.",
    ),
]
memory = ConversationBufferMemory(memory_key="chat_history")
agent_chain = initialize_agent(
    tools, llm, agent="zero-shot-react-description", memory=memory
)

result = agent_chain.run(input="How can I contact with my health insurance?")

This loader is designed to be used as a way to load data into LlamaIndex.

FAQ

Common questions

Discussion

Questions & comments · 0

Sign In Sign in to leave a comment.