repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | --- |
| #2 | title: Azure AI Search |
| #3 | --- |
| #4 | |
| #5 | [Azure AI Search](https://learn.microsoft.com/azure/search/search-what-is-azure-search/) (formerly known as "Azure Cognitive Search") provides secure information retrieval at scale over user-owned content in traditional and generative AI search applications. |
| #6 | |
| #7 | ## Usage |
| #8 | |
| #9 | ```python |
| #10 | import os |
| #11 | from mem0 import Memory |
| #12 | |
| #13 | os.environ["OPENAI_API_KEY"] = "sk-xx" # This key is used for embedding purpose |
| #14 | |
| #15 | config = { |
| #16 | "vector_store": { |
| #17 | "provider": "azure_ai_search", |
| #18 | "config": { |
| #19 | "service_name": "<your-azure-ai-search-service-name>", |
| #20 | "api_key": "<your-api-key>", |
| #21 | "collection_name": "mem0", |
| #22 | "embedding_model_dims": 1536 |
| #23 | } |
| #24 | } |
| #25 | } |
| #26 | |
| #27 | m = Memory.from_config(config) |
| #28 | messages = [ |
| #29 | {"role": "user", "content": "I'm planning to watch a movie tonight. Any recommendations?"}, |
| #30 | {"role": "assistant", "content": "How about thriller movies? They can be quite engaging."}, |
| #31 | {"role": "user", "content": "I'm not a big fan of thriller movies but I love sci-fi movies."}, |
| #32 | {"role": "assistant", "content": "Got it! I'll avoid thriller recommendations and suggest sci-fi movies in the future."} |
| #33 | ] |
| #34 | m.add(messages, user_id="alice", metadata={"category": "movies"}) |
| #35 | ``` |
| #36 | |
| #37 | ## Using binary compression for large vector collections |
| #38 | |
| #39 | ```python |
| #40 | config = { |
| #41 | "vector_store": { |
| #42 | "provider": "azure_ai_search", |
| #43 | "config": { |
| #44 | "service_name": "<your-azure-ai-search-service-name>", |
| #45 | "api_key": "<your-api-key>", |
| #46 | "collection_name": "mem0", |
| #47 | "embedding_model_dims": 1536, |
| #48 | "compression_type": "binary", |
| #49 | "use_float16": True # Use half precision for storage efficiency |
| #50 | } |
| #51 | } |
| #52 | } |
| #53 | ``` |
| #54 | |
| #55 | ## Using hybrid search |
| #56 | |
| #57 | ```python |
| #58 | config = { |
| #59 | "vector_store": { |
| #60 | "provider": "azure_ai_search", |
| #61 | "config": { |
| #62 | "service_name": "<your-azure-ai-search-service-name>", |
| #63 | "api_key": "<your-api-key>", |
| #64 | "collection_name": "mem0", |
| #65 | "embedding_model_dims": 1536, |
| #66 | "hybrid_search": True, |
| #67 | "vector_filter_mode": "postFilter" |
| #68 | } |
| #69 | } |
| #70 | } |
| #71 | ``` |
| #72 | |
| #73 | ## Using Azure Identity for Authentication |
| #74 | As an alternative to using an API key, the Azure Identity credential chain can be used to authenticate with Azure OpenAI. The list below shows the order of precedence for credential application: |
| #75 | |
| #76 | 1. **Environment Credential:** |
| #77 | Azure client ID, secret, tenant ID, or certificate in environment variables for service principal authentication. |
| #78 | |
| #79 | 2. **Workload Identity Credential:** |
| #80 | Utilizes Azure Workload Identity (relevant for Kubernetes and Azure workloads). |
| #81 | |
| #82 | 3. **Managed Identity Credential:** |
| #83 | Authenticates as a Managed Identity (for apps/services hosted in Azure with Managed Identity enabled), this is the most secure production credential. |
| #84 | |
| #85 | 4. **Shared Token Cache Credential / Visual Studio Credential (Windows only):** |
| #86 | Uses cached credentials from Visual Studio sign-ins (and sometimes VS Code if SSO is enabled). |
| #87 | |
| #88 | 5. **Azure CLI Credential:** |
| #89 | Uses the currently logged-in user from the Azure CLI (`az login`), this is the most common development credential. |
| #90 | |
| #91 | 6. **Azure PowerShell Credential:** |
| #92 | Uses the identity from Azure PowerShell (`Connect-AzAccount`). |
| #93 | |
| #94 | 7. **Azure Developer CLI Credential:** |
| #95 | Uses the session from Azure Developer CLI (`azd auth login`). |
| #96 | |
| #97 | <Note> If an API is provided, it will be used for authentication over an Azure Identity </Note> |
| #98 | To enable Role-Based Access Control (RBAC) for Azure AI Search, follow these steps: |
| #99 | |
| #100 | 1. In the Azure Portal, navigate to your **Azure AI Search** service. |
| #101 | 2. In the left menu, select **Settings** > **Keys**. |
| #102 | 3. Change the authentication setting to **Role-based access control**, or **Both** if you need API key compatibility. The default is “Key-based authentication”—you must switch it to use Azure roles. |
| #103 | 4. **Go to Access Control (IAM):** |
| #104 | - In the Azure Portal, select your Search service. |
| #105 | - Click **Access Control (IAM)** on the left. |
| #106 | 5. **Add a Role Assignment:** |
| #107 | - Click **Add** > **Add role assignment**. |
| #108 | 6. **Choose Role:** |
| #109 | - Mem0 requires the **Search Index Data Contributor** and **Search Service Contributor** role. |
| #110 | 7. **Choose Member** |
| #111 | - To assign to a User, Group, Service Principal or Managed Identity: |
| #112 | - For production it is recommended to use a service principal or managed identity. |
| #113 | - For a service principal: select **User, group, or service principal** and search for the service principal. |
| #114 | - For a managed identity: select **Managed identity** and choose the managed identity. |
| #115 | - For development, you can assign the role to a user account. |
| #116 | - For development: select **User, group, or service principal** and pick an Azure Entra ID account (the same used with `az login`). |
| #117 | 8. **Complete the Assignment:** |
| #118 | - Click **Review + Assign**. |
| #119 | |
| #120 | If you are using Azure Identity, do not set the `api_key` in the configuration. |
| #121 | ```python |
| #122 | config = { |
| #123 | "vector_store": { |
| #124 | "provider": "azure_ai_search", |
| #125 | "config": { |
| #126 | "service_name": "<your-azure-ai-search-service-name>", |
| #127 | "collection_name": "mem0", |
| #128 | "embedding_model_dims": 1536, |
| #129 | "compression_type": "binary", |
| #130 | "use_float16": True # Use half precision for storage efficiency |
| #131 | } |
| #132 | } |
| #133 | } |
| #134 | ``` |
| #135 | |
| #136 | ### Environment Variables to Use Azure Identity Credential |
| #137 | * For an Environment Credential, you will need to setup a Service Principal and set the following environment variables: |
| #138 | - `AZURE_TENANT_ID`: Your Azure Active Directory tenant ID. |
| #139 | - `AZURE_CLIENT_ID`: The client ID of your service principal or managed identity. |
| #140 | - `AZURE_CLIENT_SECRET`: The client secret of your service principal. |
| #141 | * For a User-Assigned Managed Identity, you will need to set the following environment variable: |
| #142 | - `AZURE_CLIENT_ID`: The client ID of the user-assigned managed identity. |
| #143 | * For a System-Assigned Managed Identity, no additional environment variables are needed. |
| #144 | |
| #145 | ### Developer Logins for Azure Identity Credential |
| #146 | * For an Azure CLI Credential, you need to have the Azure CLI installed and logged in with `az login`. |
| #147 | * For an Azure PowerShell Credential, you need to have the Azure PowerShell module installed and logged in with `Connect-AzAccount`. |
| #148 | * For an Azure Developer CLI Credential, you need to have the Azure Developer CLI installed and logged in with `azd auth login`. |
| #149 | |
| #150 | Troubleshooting tips for [Azure Identity](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/identity/azure-identity/TROUBLESHOOTING.md#troubleshoot-environmentcredential-authentication-issues). |
| #151 | |
| #152 | |
| #153 | ## Configuration Parameters |
| #154 | |
| #155 | | Parameter | Description | Default Value | Options | |
| #156 | | --- | --- | --- | --- | |
| #157 | | `service_name` | Azure AI Search service name | Required | - | |
| #158 | | `api_key` | API key of the Azure AI Search service | Optional | If not present, the [Azure Identity](#using-azure-identity-for-authentication) credential chain will be used | |
| #159 | | `collection_name` | The name of the collection/index to store vectors | `mem0` | Any valid index name | |
| #160 | | `embedding_model_dims` | Dimensions of the embedding model | `1536` | Any integer value | |
| #161 | | `compression_type` | Type of vector compression to use | `none` | `none`, `scalar`, `binary` | |
| #162 | | `use_float16` | Store vectors in half precision (Edm.Half) | `False` | `True`, `False` | |
| #163 | | `vector_filter_mode` | Vector filter mode to use | `preFilter` | `postFilter`, `preFilter` | |
| #164 | | `hybrid_search` | Use hybrid search | `False` | `True`, `False` | |
| #165 | |
| #166 | ## Notes on Configuration Options |
| #167 | |
| #168 | - **compression_type**: |
| #169 | - `none`: No compression, uses full vector precision |
| #170 | - `scalar`: Scalar quantization with reasonable balance of speed and accuracy |
| #171 | - `binary`: Binary quantization for maximum compression with some accuracy trade-off |
| #172 | |
| #173 | - **vector_filter_mode**: |
| #174 | - `preFilter`: Applies filters before vector search (faster) |
| #175 | - `postFilter`: Applies filters after vector search (may provide better relevance) |
| #176 | |
| #177 | - **use_float16**: Using half precision (float16) reduces storage requirements but may slightly impact accuracy. Useful for very large vector collections. |
| #178 | |
| #179 | - **Filterable Fields**: The implementation automatically extracts `user_id`, `run_id`, and `agent_id` fields from payloads for filtering. |