This project implements two Azure Function APIs:
- IndexDocuments: Accepts a document link (PDF or DOCX) and indexes it into Azure AI search.
- QueryKnowledgeBase: Queries the indexed documents and retrieves relevant information using OpenAI's GPT model.
- Reads documents from Azure Blob Storage.
- Splits document content into chunks.
- Generates embeddings using OpenAI's
text-embedding-3-smallmodel. - Indexes chunks into Azure AI search.
- Handles errors and returns a status message.
- Takes a user query and converts it into a vector embedding.
- Searches through the indexed content using vector search.
- Uses GPT to return relevant information or null if no relevant information is found.
- Azure Functions
- Azure AI Search
- Azure OpenAI
- Python
- Postman
Ensure the following environment variables are set:
AZURE_OPENAI_ENDPOINT: Azure OpenAI API endpoint.AZURE_OPENAI_API_KEY: Azure OpenAI API key.AZURE_OPENAI_API_VERSION: OpenAI API version.AZURE_SEARCH_ENDPOINT: Azure Search API endpoint.AZURE_SEARCH_KEY: Azure Search API key.SYSTEM_MESSAGE_TEMPLATE: The system message template for GPT responses.
-
Clone this repository:
git clone https://github.com/ShashankGowni/Azure-Function-App-using-Vector-search
-
Navigate to the project folder:
cd Azure-Function-App-using-Vector-search -
Install the required dependencies:
pip install -r requirements.txt
-
Set the necessary environment variables:
- For local development, create a
.envfile or set them in the terminal.
- For local development, create a
To run the function app locally, use the Azure Functions Core Tools:
func start-
IndexDocuments API
- Request Type: POST
- Endpoint:
http://localhost:<port>/api/IndexDocuments - Request Body:
{ "doc_link": "https://yourblobstorageurl.com/yourfile.pdf" } - Success Response:
{ "status": "COMPLETED", "error": null } - Failure Response:
{ "status": "FAILED", "error": "Document format is not supported." }
-
QueryKnowledgeBase API
- Request Type: GET
- Endpoint:
http://localhost:<port>/api/QueryKnowledgeBase?query=What%20is%20Azure&index_name=your_index_name - Success Response:
{ "response": "Azure is a cloud computing service from Microsoft.", "error": null } - Failure Response:
{ "response": null, "error": null }

.png)