skip to Main Content

I have a database of records in Cosmos DB. I want to write something that would allow me to, given a particular record (let’s say it has a description), find the top 5 records with the most similar descriptions to that particular record. What would be the best Azure service to accomplish this?

I looked into text analytics, but it didn’t seem to have the functionality I’d need. Maybe I’m wrong, open to any suggestions!

2

Answers


  1. It could be worth looking into Power BI. I’ve never worked with Cosmos DB but the Microsoft documentation should help you get started https://learn.microsoft.com/en-us/azure/cosmos-db/nosql/powerbi-visualize

    Login or Signup to reply.
    1. Using azure cognitive search service, you can retrieve top 5 records having similar description or containing a specific word.
    2. I have a table in cosmos DB with data as shown below,
      enter image description here
    [
      {
         "id": "1",
        "category": "personal",
        "name": "groceries",
       "description": "Pick up apples and strawberries.",
       "isComplete": false,
      "_rid": "Le4RAMNCjb4BAAAAAAAAAA==",
    "_self":"dbs/Le4RAA==/colls/Le4RAMNCjb4=/docs/Le4RAMNCjb4BAAAAAAAAAA==/",
    "_etag": ""00000ab3-0000-0700-0000-636393880000"",
    "_attachments": "attachments/",
    "_ts": 1667470216
       },
    {
    "id": "2",
    "category": "social",
    "name": "activity",
    "description": "social activity statu",
    "isComplete": false,
    "_rid": "Le4RAMNCjb4CAAAAAAAAAA==",
    "_self": "dbs/Le4RAA==/colls/Le4RAMNCjb4=/docs/Le4RAMNCjb4CAAAAAAAAAA==/",
    "_etag": ""00000bb3-0000-0700-0000-6363943e0000"",
    "_attachments": "attachments/",
    "_ts": 1667470398
       },
    {
    "id": "3",
    "category": "personal",
    "name": "rent",
    "description": "transfer rent and pick up apples ",
    "isComplete": false,
    "_rid": "Le4RAMNCjb4DAAAAAAAAAA==",
    "_self": "dbs/Le4RAA==/colls/Le4RAMNCjb4=/docs/Le4RAMNCjb4DAAAAAAAAAA==/",
    "_etag": ""00000cb3-0000-0700-0000-636394b70000"",
    "_attachments": "attachments/",
    "_ts": 1667470519
     },
    {
      "id": "4",
    "category": "professional",
    "name": "activity",
    "description": "Pot luck activity. Bring apples and snacks",
    "isComplete": false,
    "_rid": "Le4RAMNCjb4EAAAAAAAAAA==",
    "_self": "dbs/Le4RAA==/colls/Le4RAMNCjb4=/docs/Le4RAMNCjb4EAAAAAAAAAA==/",
    "_etag": ""000012b3-0000-0700-0000-636395890000"",
    "_attachments": "attachments/",
    "_ts": 1667470729
    },
     {
    "id": "5",
    "category": "personal",
    "name": "Diet",
    "description": "It is suggested to add apples in your diet",
    "isComplete": false,
    "_rid": "Le4RAMNCjb4FAAAAAAAAAA==",
    "_self": "dbs/Le4RAA==/colls/Le4RAMNCjb4=/docs/Le4RAMNCjb4FAAAAAAAAAA==/",
    "_etag": ""000013b3-0000-0700-0000-636395d00000"",
    "_attachments": "attachments/",
    "_ts": 1667470800
    },
    {
    "id": "6",
    "category": "personal",
    "name": "Snacks",
    "description": "Fruit salad including apples, grapes, banana and mango",
    "isComplete": false,
    "_rid": "Le4RAMNCjb4GAAAAAAAAAA==",
    "_self": "dbs/Le4RAA==/colls/Le4RAMNCjb4=/docs/Le4RAMNCjb4GAAAAAAAAAA==/",
    "_etag": ""00001eb3-0000-0700-0000-6363961e0000"",
    "_attachments": "attachments/",
    "_ts": 1667470878
    },
    {
    "id": "7",
    "category": "personal",
    "name": "groceries",
    "description": "bring apples and oats.",
    "isComplete": false,
    "_rid": "Le4RAMNCjb4HAAAAAAAAAA==",
    "_self": "dbs/Le4RAA==/colls/Le4RAMNCjb4=/docs/Le4RAMNCjb4HAAAAAAAAAA==/",
    "_etag": ""00002bb3-0000-0700-0000-636399c80000"",
    "_attachments": "attachments/",
    "_ts": 1667471816
     }
      ]   
    
    1. The table has column with name description. Total six records in table contains the term apples in description column.
    2. Created a search service.
      enter image description here
    3. Selected Azure cosmos DB as data source, created index and created indexer.

    Data source

    enter image description hereindex

    enter image description hereindexer

    enter image description here
    6. Using Azure search explorer, given a query term as below to get only top 5 records containing term apples.

    $top=5&search=’apples’
    enter image description here
    Here is the output of above query,

    {
    "@odata.context": "https://<searchservicename>.search.windows.net/indexes('cosmosdb-index')/$metadata#docs(*)",
    "value": [
    {
    "@search.score": 0.26742277,
    "id": "3",
    "category": "personal",
    "name": "rent",
    "description": "transfer rent and pick up apples ",
    "isComplete": false,
    "rid": "TGU0UkFNTkNqYjREQUFBQUFBQUFBQT090"
      },
    {
    "@search.score": 0.25811607,
    "id": "6",
    "category": "personal",
    "name": "Snacks",
    "description": "Fruit salad including apples, grapes, banana and mango",
    "isComplete": false,
    "rid": "TGU0UkFNTkNqYjRHQUFBQUFBQUFBQT090"
     },
    {
    "@search.score": 0.20521776,
    "id": "7",
    "category": "personal",
    "name": "groceries",
    "description": "bring apples and oats.",
    "isComplete": false,
    "rid": "TGU0UkFNTkNqYjRIQUFBQUFBQUFBQT090"
     },
    {
    "@search.score": 0.2034302,
    "id": "1",
    "category": "personal",
    "name": "groceries",
    "description": "Pick up apples and strawberries.",
    "isComplete": false,
    "rid": "TGU0UkFNTkNqYjRCQUFBQUFBQUFBQT090"
    },
    {
    "@search.score": 0.16281115,
    "id": "4",
    "category": "professional",
    "name": "activity",
    "description": "Pot luck activity. Bring apples and snacks",
    "isComplete": false,
    "rid": "TGU0UkFNTkNqYjRFQUFBQUFBQUFBQT090"
         }
      ]
    }
    

    Reference: https://learn.microsoft.com/en-us/azure/cosmos-db/nosql/quickstart-portal#add-data-to-your-database

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search