Skip to content

Providing more context

When you ask a question, you can provide additional user data to the answer session. This is useful when you want to provide a more personalized experience to your users.

For example, if you know that the user is a beginner in programming, you can provide a more detailed explanation of the concepts you’re talking about:

const answer = await answerSession.ask({
term: "What is Orama?",
userData: {
userLevel: "beginner"
}
});

Just like the userContext, the userData can be a string or an object:

const answer = await answerSession.ask({
term: "What is Orama?",
userData: "The user is a beginner in programming"
});

What’s the difference between userContext and userData?

The main difference between userContext and userData is that the userData is specific to a single answer request, while the userContext is global to the entire answer session.

Of course, Orama will remember the userData in subsequent answer requests, but will tend to forget it after a while. So, if that data is important to you, you should either provide it in every answer request, or use the userContext instead.