How to make Multi User Role Based Access Chatbot which generate different answers for each user depending on their knowledge base?

I need help with some work for my website : I need to create a RAG (Retrieval Augmentation Generation) model for making one chatbot like you. But the trick is I have multiple users, and each user has access to a different knowledge base; one user can’t see the other user’s content. I want one chatbot using any good models API, I have about 5 users, and I have some user-specific PDF Files I want to store them in a server not in a local machine, and access data from the server.

Details about documents:
- I want to store all the documents in a single folder/location of that specific user. Such as User1/user1_Doc1, user1_doc2…etc, User2/user2_Doc1,user2_doc2….etc……

Details about users:
The users are employees of the company, not customers. For a specific user: there are some sets of documents each in their folder. so like that there are several folders as many as several users. One user’s knowledge base is different from another user’s. Assume there are no common documents. Now for this user’s data when he logs in to the portal - he should not navigate through the whole website instead ask the chatbot what document he needs and the model should output the document or the contents from the document like summarising the content and link for the that document to download.

  • Examples of documents are Form 16, Degree of education certificates, Tax invoices, Salary Slips…etc
  • Should be first able to create an account for each user [up to 5 accounts] and then log in.
  • Define user roles like admin, user 1, user 2, …etc.
  • How can I Map user roles to permissions that control features and data access that that user can only access, as every user has a different set of documents to access data from?

Help me achieve this by giving a detailed solution. give a very detailed solution to achieve this first. Let’s think about the tech stack later after I decide on a solution. Delve deep into how I can have user-based chatbot system as this is the important part.

How can i achieve this?

For the frontend use “Streamlit” For the backend use “FastAPI”
use the “LangChain” library for Chatbot modeling
For storing data use - GCP
For access control use - Firebase

I’d use the Assistants endpoint with unique threads for each user, and then host it through unique GCP endpoints (or paths).

1 Like

Hey hrithiksagar2000 - Welcome to the community,

I would also use assistant’s API and maintain session states across user logins and that should solve the problem for access. You can have tools like file search and also have functions defined which embeds the user documents during run time and vector DBs can be used for RAG (or have it setup when the user logs in).
Cheers!

1 Like

Hey Hrithik, I have an example implementation and code for implementing role based access controls with LLMs on [github](I have an example implementation and code for implementing role based access controls with LLMs on github rag_with_rbac (can’t include links here but you can search with that term)
You can take a look at the code (it’s in the index_utils module).

Feedback welcome!

1 Like

github dot com slash abhishek-kumar slash rag_with_rbac

2 Likes

It doesn’t matter which model you use - you can change that part of the code.

  1. Embeddings.
from langchain.embeddings import SentenceTransformerEmbeddings
embedding=SentenceTransformerEmbeddings(model_name="all-MiniLM-L6-v2")
# Use this in place of OpenAIEmbeddings in the code
  1. Switch from OpenAI LLM to Llama: very easy

In the method get_llm(...) (in streamlit_app.py), you will see:

def get_llm(openai_api_key) -> OpenAI:
    return OpenAI(temperature=0.2, openai_api_key=openai_api_key)

Replace it to the following:

from langchain_community.llms import LlamaCpp

def get_llm() -> LlamaCpp:
    return LlamaCpp(...)

(You might need to install the packages, follow the langchain llamacpp docs. Unfortunately I cannot include links here but you can find the documentation page)

1 Like

I think you can use chatGPT to do this change.

Thank you Abhishek!! very helpful.