Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add Azure AI Search + Azure OpenAI RAG recipe notebook #675

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

farzad528
Copy link

Azure AI Search RAG Example Using Docling

This notebook demonstrates how to build a Retrieval Augmented Generation (RAG) system using Docling and Azure AI Search. The example showcases document parsing, chunking, vector search integration, and RAG query implementation.

Checklist:

  • Documentation has been updated, if necessary.
  • Examples have been added, if necessary.
  • [] Tests have been added, if necessary.

Copy link

mergify bot commented Jan 4, 2025

Merge Protections

Your pull request matches the following merge protections and will not be merged until they are valid.

🟢 Enforce conventional commit

Wonderful, this rule succeeded.

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\(.+\))?(!)?:

@farzad528
Copy link
Author

farzad528 commented Jan 5, 2025

@vagenas @pablocastro can you review :)

" print(\"MPS GPU is enabled.\")\n",
"else:\n",
" raise EnvironmentError(\n",
" \"No GPU or MPS device found. Please check your environment and ensure GPU or MPS support is configured.\"\n",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not all the other examples seem to require a GPU/MPS backend. Is this a hard requirement?

"AZURE_OPENAI_ENDPOINT = os.getenv(\"AZURE_OPENAI_ENDPOINT\")\n",
"AZURE_OPENAI_API_KEY = os.getenv(\"AZURE_OPENAI_API_KEY\")\n",
"AZURE_OPENAI_CHAT_MODEL = os.getenv(\"AZURE_OPENAI_CHAT_MODEL\")\n",
"AZURE_OPENAI_API_VERSION = os.getenv(\"AZURE_OPENAI_API_VERSION\")\n",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could include a default version to save folks from having to go to the docs to chase a good version number.

"source": [
"# Part 0: Prerequisites\n",
" - Azure AI Search resource\n",
" - Azure OpenAI resource with deployed embeddings & chat models\n",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Further down you make the assumption that the embedding model is text-embedding-3-small, maybe we could call this out here so folks know what to deploy in their Azure OpenAI instance?

" embedding_vector = embed_text(chunk_text)\n",
" upload_docs.append(\n",
" {\n",
" \"chunk_id\": str(uuid.uuid4()),\n",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a previous cell you created a list of tuples (chunk id, chunk text), but here you're not using the id and generating a GUID instead. The previously generated chunk id doesn't seem to be used, seems you only need one thing, either the chunk ids you generated before (then you don't need the new GUID here, use the first element of the tuple instead), or don't generate chunk ids in the previous cell (and in that case it looks like you don't need to create all_chunks at all, since you could just enumerate the original doc_chunks instead.

" subset = upload_docs[i : i + BATCH_SIZE]\n",
" resp = search_client.upload_documents(documents=subset)\n",
" console.print(\n",
" f\"Uploaded batch {i} -> {i+len(subset)}; success: {resp[0].succeeded}, status code: {resp[0].status_code}\"\n",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean to check if all succeeded/any failed? Aren't you just checking the first doc above?

"source": [
"from azure.search.documents.models import VectorizableTextQuery\n",
"\n",
"def generate_chat_response(prompt: str, system_message: str = None):\n",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this method creates a new message list each time, there's no chat history preserved between turns (e.g. can't make follow up questions). I assume this was on purpose, but calling it out just in case.

@vagenas vagenas self-assigned this Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants