{ "cells": [ { "cell_type": "markdown", "id": "2dd8cd46", "metadata": {}, "source": [ "# Azure Postgres Vector Store\n", "In this notebook we are going to show how to use [Azure Postgresql](https://azure.microsoft.com/en-au/products/postgresql) and [pg_diskann](https://github.com/microsoft/DiskANN) to perform vector searches in LlamaIndex. \n", "Please note that this document is mostly based on the document for [PostgreSQL integration](https://docs.llamaindex.ai/en/stable/examples/vector_stores/postgres/) to simplify the transition." ] }, { "cell_type": "code", "execution_count": null, "id": "5d4b9721", "metadata": {}, "outputs": [], "source": [ "!pip install llama-index" ] }, { "cell_type": "code", "execution_count": null, "id": "c95fd172", "metadata": {}, "outputs": [], "source": [ "%load_ext sql" ] }, { "cell_type": "code", "execution_count": null, "id": "3412ab2a", "metadata": {}, "outputs": [], "source": [ "import subprocess\n", "import os\n", "from urllib.parse import quote_plus\n", "\n", "cmd = [\n", " \"az\",\n", " \"account\",\n", " \"get-access-token\",\n", " \"--resource\",\n", " \"https://ossrdbms-aad.database.windows.net\",\n", " \"--query\",\n", " \"accessToken\",\n", " \"--output\",\n", " \"tsv\",\n", "]\n", "\n", "try:\n", " token = subprocess.check_output(cmd, text=True).strip()\n", "except subprocess.CalledProcessError as exc:\n", " raise RuntimeError(f\"Failed to run command: {exc}\") from exc\n", "os.environ[\"PGPASSWORD\"] = token" ] }, { "cell_type": "code", "execution_count": null, "id": "fa5389a9", "metadata": {}, "outputs": [ { "data": { "text/html": [ "Connecting to 'postgresql://'" ], "text/plain": [ "Connecting to 'postgresql://'" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%sql postgresql://" ] }, { "cell_type": "code", "execution_count": null, "id": "a35ff87e", "metadata": {}, "outputs": [ { "data": { "text/html": [ "Running query in 'postgresql://'" ], "text/plain": [ "Running query in 'postgresql://'" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "