How to add vector index when you import data from your azure sql database?

suraj pawar vadeghar 10 Reputation points
2024-08-21T20:16:18.6533333+00:00

I created azure sql index by connecting data to my azure sql db. How do I create a vector index? The reason Im asking is because when I create an LLM using azure AI studio, the indexed data is not yielding me right results for the queries I ask.

User's image

Azure AI Search
Azure AI Search
An Azure search service with built-in artificial intelligence capabilities that enrich information to help identify and explore relevant content at scale.
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Amira Bedhiafi 39,106 Reputation points Volunteer Moderator
    2025-10-16T19:21:53.27+00:00

    Hello Suraj !

    Thank you for posting on Microsoft Learn Q&A.

    You make your search index contain a vector field and you populate that field with embeddings either pre-computed in SQL or computed by a skillset during indexing. The vector index size 0 bytes in your screenshot means that your index has no vector field or it’s empty.

    You can add a vector field with profile to your index :

    {
      "name": "azuresql-index",
      "fields": [
        { "name": "id", "type": "Edm.String", "key": true, "filterable": true },
        { "name": "content", "type": "Edm.String", "searchable": true },
        { "name": "embedding", "type": "Collection(Edm.Single)", "searchable": true,
          "dimensions": 1536,                   
          "vectorSearchProfile": "v-hnsw" }
      ],
      "vectorSearch": {
        "algorithms": [{ "name": "hnsw", "kind": "hnsw" }],
        "profiles":   [{ "name": "v-hnsw", "algorithm": "hnsw" }]
      }
    }
    

    and create a skillset that generates embeddings from your text column and maps them to /document/embedding:

    {
      "name": "azuresql-embed-skillset",
      "skills": [
        {
          "@odata.type": "#Microsoft.Skills.Text.EmbeddingSkill",
          "name": "make-embeddings",
          "context": "/document",
          "inputs": [{ "name": "text", "source": "/document/content" }],
          "outputs": [{ "name": "embeddings", "targetName": "embedding" }],
          "modelVersion": "text-embedding-3-large"   // or your model
        }
      ]
    }
    

    then wire your indexer to the skillset and map the output:

    {
      "name": "azuresql-indexer",
      "dataSourceName": "azuresql-datasource",
      "targetIndexName": "azuresql-index",
      "skillsetName": "azuresql-embed-skillset",
      "outputFieldMappings": [
        { "sourceFieldName": "/document/embedding", "targetFieldName": "embedding" }
      ],
      "fieldMappings": [
        { "sourceFieldName": "Id", "targetFieldName": "id" },
        { "sourceFieldName": "Content", "targetFieldName": "content" }
      ]
    }
    

    Run the indexer you will see the vector index size will grow from 0 once embeddings are stored.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.