LightRAG icon indicating copy to clipboard operation
LightRAG copied to clipboard

[Question]: User isolation

Open wangzhen38 opened this issue 10 months ago • 4 comments

Do you need to ask a question?

  • [ ] I have searched the existing question and discussions and this question is not already answered.
  • [ ] I believe this is a legitimate question, not just a bug or feature request.

Your Question

Currently, it appears that all users are sharing the same database? If we want to allow users to store and access data in their own databases, how should we implement this? Ths~

Additional Context

No response

wangzhen38 avatar Feb 25 '25 08:02 wangzhen38

Have you tried to manage this topic by workspaces?

CoachbotAI avatar Feb 25 '25 14:02 CoachbotAI

Using a different workspace per user will just separate the metadata (docs, response cache, chunks, etc.). But changing the workspace does not actually do anything on the database level I believe.

I'm looking for solutions myself as well. Since I'm storing sensitive user data in the graph database, separating the user data is vital.

Proposal

My current thoughts are to pass a custom graph database instance instead of a string of the database;

graph_storage = get_graph_storage_for_user(user_id)  # This could be a separate db or a separate schema/table in a db
LightRAG(
    working_dir=user_dir,
    embedding_func=openai_embed,
    graph_storage=graph_storage,  # Instead of passing a string (which is currently the limitation)
    llm_model_func=gpt_4o_mini_complete,
)

I'll likely open my own issue/question to see why the authors chose to pass a string instead of a graph storage instance directly. I personally think it'd simplify some things, while allowing more extensibility.

JoramMillenaar avatar Mar 01 '25 20:03 JoramMillenaar

Update: I found an existing solution; the namespace_prefix argument. As the docstring states; "Prefix for namespacing stored data across different environments.". So, this would allow you to put data in separate environments 🙌. Hope it helps

        rag_instances[user_id] = LightRAG(
            namespace_prefix=user_id,
            working_dir=user_dir,
            embedding_func=openai_embed,
            graph_storage="Neo4JStorage",
            llm_model_func=gpt_4o_mini_complete
        )

JoramMillenaar avatar Mar 03 '25 22:03 JoramMillenaar

I currently using the docs filtering, so when user query, it only retrieve filtered docs correlated to the user.

husaynirfan1 avatar Mar 25 '25 18:03 husaynirfan1