Hello johananmahendran,
Welcome to the Microsoft Q&A and thank you for posting your questions here.
I understand that your scenario focused on dynamically customize web app for different users and user groups.
This is a simplified and optimized best practices approach:
- Use Azure Cosmos DB or MongoDB with a structure like:
Retrieve chat history using:{ "userId": "user123", "timestamp": "2024-07-25T10:30:00Z", "chat": "What are the latest company policies?", "response": "Refer to policy document X." }
chat_history = collection.find({"userId": user_id}).sort("timestamp", -1)
- Instead of relying on RBAC, use index metadata filtering to Implement Document-Level Security in Azure AI Search, by following the steps below: Step 1: When indexing documents in Azure AI Search, add a user-group field to store Metadata in the Index:
Ensure{ "id": "doc123", "content": "Confidential sales report", "allowedGroups": ["sales", "executives"] }
allowedGroups
is retrievable and filterable in the index schema. Step 2: When a user searches, extract their assigned groups from Microsoft Entra ID (Azure AD) to apply Filters Dynamically in Queries:
Then, filter search queries dynamically:user_groups = get_user_groups(user_id) # ["sales", "marketing"]
This ensures the user only sees documents matching at least one of their groups.group_filter = " OR ".join([f"allowedGroups eq '{group}'" for group in user_groups]) search_results = search_client.search(query, filter=group_filter)
- Putting into consideration your frontend (React TypeScript). Use MSAL React (
@azure/msal-react
) to authenticate users and obtain their group claims from Microsoft identity provider. - Then, send group claims to the backend with search requests. Your backend (Python) will extract the user's groups from the token and apply document filtering dynamically.
- This is an Optional - To dynamically Customize Chatbot Per User. If you want different chatbot responses per user group, consider:
- Different Prompts, you will have to customize GPT behavior based on the user's group.
- Different Knowledge Bases, use separate vector databases for each group.
- And Azure OpenAI on Your Data, you will have to create multiple indexes per group.
I hope this is helpful! Do not hesitate to let me know if you have any other questions.
Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful.