Skip to content

Commit

Permalink
docs: improves docs
Browse files Browse the repository at this point in the history
  • Loading branch information
micheleriva committed Jul 24, 2024
1 parent 7512ca9 commit 77ba63c
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,6 @@ The main difference between `userContext` and `userData` is that the `userData`

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.


## Aborting Answers Generation

In any moment in time (when a user cancels an answer request, for example) you can abort an answer by using the `.abortAnswer` function:
Expand Down Expand Up @@ -1007,7 +1006,63 @@ This will trigger the `onAnswerAborted` event, which will simply return a `true`
</TabItem>
</Tabs>

## Getting all the Messages
## Getting related queries

When creating answer sessions, you may want to provide your users with a list of related queries that they can use to get more information about a specific topic. You can do this by using the `related` parameter:

When asking for `"question"` (default) related queries, Orama will return an array of related queries in a question format. For example, if the user asks for: "What is Orama?", Orama will return an array of related queries like: `["How does Orama work?", "Why is Orama the best?", "How do I run vector search?"]`.

If the format is `"query"`, Orama will return an array of related queries in a query format. For example, if the user asks for: "What is Orama?", Orama will return an array of related queries like: `["How Orama works", "Why Orama is the best", "Vector search with Orama"]`.

<Tabs syncKey="sdk">
<TabItem label="JavaScript" icon="seti:javascript">
```javascript copy
const answerSession = orama.createAnswerSession({
events: {
onRelatedQueries: (relatedQueries) => {
console.log(relatedQueries);
// ["How Orama works", "Why Orama is the best", "Vector search with Orama"]
},
}
});

await answerSession.ask({
term: "What is Orama?",
related: {
howMany: 3, // How many related queries you want to get. Maximum is 5.
format: 'query'
}
});
```
</TabItem>
<TabItem label="Swift" icon="seti:swift">
```swift copy
```swift copy
let answer = try await answerSession.ask(params: AnswerParams.AskParams(
query: "What is Orama?",
userData: "The user is a beginner in programming",
related: AnswerParams<MyDoc>.RelatedQueries(howMany: 3, format: "query")
))
```
</TabItem>
<TabItem label="Kotlin" icon="seti:kotlin">
```kotlin copy
print("coming soon")
```
</TabItem>
<TabItem label="Python" icon="seti:python">
```python copy
print("coming soon")
```
</TabItem>
<TabItem label="PHP" icon="seti:php">
```php copy
// coming soon
```
</TabItem>
</Tabs>

## Getting all the messages

At any point in time, you can retrieve all the messages by calling the `.getMessages` function:

Expand Down Expand Up @@ -1089,7 +1144,7 @@ Sometimes, the user may want to regenerate the last answer. You can do this by c

// Regenerate the answer
// "stream" is true by default, but you can set it to false if you want to get the entire answer at once
let answer = try await answerSession.regenerateLast(params: AnswerParams.RegenerateParams(stream: false))
let answer = try await answerSession.regenerateLast(stream: false)

// Check the messages
let messages = answerSession.getMessages()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ The client exposes a simple `search` method that can be used to query the index:
</TabItem>
<TabItem label="Swift" icon="seti:swift">
```swift copy
import OramaCloud
import OramaCloudClient

struct MyDoc: Codable {
let title: String
Expand Down Expand Up @@ -267,42 +267,18 @@ With the Orama Faceted Search API, users can filter their search results by vari

Given the following Orama schema:

<Tabs syncKey="sdk">
<TabItem label="JavaScript" icon="seti:javascript">
```json
{
title: "string",
description: "string",
categories: {
primary: "string",
secondary: "string",
},
rating: "number",
isFavorite: "boolean",
}
```
</TabItem>
<TabItem label="Swift" icon="seti:swift">
```swift copy
print("coming soon")
```
</TabItem>
<TabItem label="Kotlin" icon="seti:kotlin">
```kotlin copy
print("coming soon")
```
</TabItem>
<TabItem label="Python" icon="seti:python">
```python copy
print("coming soon")
```
</TabItem>
<TabItem label="PHP" icon="seti:php">
```php copy
// coming soon
```
</TabItem>
</Tabs>
```json title=schema.json
{
"title": "string",
"description": "string",
"categories": {
"primary": "string",
"secondary": "string",
},
"rating": "number",
"isFavorite": "boolean",
}
```

Orama will be able to generate facets at search-time based on the schema. To do so, we need to specify the `facets` property in the `search` configuration:

Expand All @@ -311,6 +287,7 @@ Orama will be able to generate facets at search-time based on the schema. To do
```js
const results = await client.search({
term: "Movie about cars and racing",
mode: "hybrid",
properties: ["description"],
facets: {
"categories.primary": {
Expand Down Expand Up @@ -338,7 +315,34 @@ Orama will be able to generate facets at search-time based on the schema. To do
</TabItem>
<TabItem label="Swift" icon="seti:swift">
```swift copy
print("coming soon")
import OramaCloudClient

struct MyDoc: Codable {
let title: String
let description: String
}

let clientParams = OramaClientParams(endpoint: "<Your Orama Cloud Endpoint>", apiKey: "<Your Orama Cloud API Key>")
let client = OramaClient(params: clientParams)

let searchParams = ClientSearchParams.builder(
term: "Movie about cars and racing",
mode: .hybrid
)
.properties(["description"]) // optional
.facets([
"category.primary": .string(limit: 3, order: .desc),
"category.secondary": .string(limit: 2, order: .desc),
"rating": .number(ranges: [
ClientSearchParams.Facet.NumberRange(from: 0, to: 3),
ClientSearchParams.Facet.NumberRange(from: 3, to: 7),
ClientSearchParams.Facet.NumberRange(from: 7, to: 10),
]),
"isFavorite": .boolean(isTrue: true, isFalse: true),
])
.build()

let searchResults: SearchResults<MyDoc> = try await client.search(query: searchParams)
```
</TabItem>
<TabItem label="Kotlin" icon="seti:kotlin">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Once you have at least one index containing vectors, you can perform hybrid sear
</TabItem>
<TabItem label="Swift" icon="seti:swift">
```swift copy
import OramaCloud
import OramaCloudClient

struct MyDoc: Encodable & Decodable {
let title: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Once you have at least one index containing vectors, you can perform vector sear
</TabItem>
<TabItem label="Swift" icon="seti:swift">
```swift copy
import OramaCloud
import OramaCloudClient

struct MyDoc: Encodable & Decodable {
let title: String
Expand Down

0 comments on commit 77ba63c

Please sign in to comment.