Back to Auth0.ai
    mock

    You are viewing use cases docs. Start a new chat to explore the demo.

    Use case

    Explained Prompt: Show me forecast for ZEKO

    Authorization for RAG

    Only retrieve documents users have access to. Avoid leaking data to a user that should not have access to it.

    Authorization for RAG

    Scenario

    When a user submits a forecast inquiry for a specific company, like Zeko, the chatbot will generate a response using relevant documents retrieved from the vector store. By default, Market0 will only include publicly available filings. However, users may also have access to analyst-level forecasts, providing them with additional insights when the response is generated.


    OKTA FGA (Fine-Grained Authorization) is used to check which documents the user has access to based on their permissions.

    How it works

    1. User Forecast Request: The user requests a forecast for a specific company, such as ZEKO.
    2. Document Retrieval: Market0 handles the request and employs a retriever to search its vector store for documents relevant to the requested information. It applies filters to ensure only the documents the user has access to are considered.
    3. Response Generation: Based on the retrieved documents, Market0 compiles a tailored response for the user. Depending on user's permissions the response could be based on analyst-level forecasts.

    Explore the code

    To implement this functionality, we use several helper functions and components, detailed below.

    FGARetriever (withCheckPermission)
    1// Get the db vector store 2const vectorStore = await getDocumentsVectorStore(); 3 4// Create a retriever that filters the documents by symbol 5const retriever = vectorStore.asRetriever({ 6 filter: { symbol }, 7}); 8 9// Create a Retriever Wrapper that filters the documents by user access 10const fgaRetriever = new FGARetriever({ 11 retriever, 12 fgaClient, 13 buildQuery: (doc) => ({ 14 user: `user:${claims.sub}`, 15 relation: RELATION.CAN_VIEW_DOCS, 16 object: `doc:${doc.metadata.id}`, 17 }) 18}); 19 20const docs = await fgaRetriever.invoke('forecast of ZEKO'); 21console.dir(docs);