Skip to content

Commit dea6e35

Browse files
committed
docs: add example scripts and instructions.
1 parent f6c4ebd commit dea6e35

File tree

6 files changed

+80
-0
lines changed

6 files changed

+80
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ target
22
model
33
ort
44

5+
example/conversations.json
6+
57
# pixi environments
68
.pixi
79
*.egg-info

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,38 @@ The endpoint will return a list of items with their ID and the similarity score
4444
You can optionally add a `limit` query parameter which will set a limit on how many items are
4545
returned, for example: `POST /search?limit=20`. The default limit is `10`.
4646

47+
## Example
48+
49+
The repo includes a quick example of how to use it to search a database of chat messages using Deno.
50+
51+
```bash
52+
cd example
53+
54+
# First we need to start the search services
55+
docker compose up -d
56+
57+
# Then we need to download the conversation database. That will download
58+
# the `conversations.json` file containing a bunch of sample messages.
59+
./download-conversations.sh
60+
61+
# Now we need to index the messages. This may take a while to index the 188k
62+
# messages, but you can search the messages while they are being indexed and
63+
# if you don't care to index all of them you can cancel it at any time and
64+
# all of the messages that have already been indexed will still be searchable.
65+
deno run -A indexConversations.ts
66+
67+
# After that's done ( or during indexing in another terminal ), we can search
68+
# for chat messages.
69+
deno run -A search.ts Do you like dogs?
70+
```
71+
72+
Check out the scripts in the `example` folder to see how easy it is to search and index messages!
73+
74+
### Qdrant Dashboard
75+
76+
You can also access the QDrant web dashboard after running `docker compose up -d` by going to
77+
<http://localhost:6333/dashboard#/collections>.
78+
4779
## Deployment
4880

4981
The service is easily deployed, along with Qdrant, using docker compose:

example/conversations.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const conversations: {
2+
[key: string]: {
3+
article_url: string;
4+
config: string;
5+
content: {
6+
message: string;
7+
agent: string;
8+
sentiment: string;
9+
knowledge_source: string[];
10+
turn_rating: string;
11+
}[];
12+
};
13+
} = JSON.parse(await Deno.readTextFile("./conversations.json"));
14+
15+
export const messages: string[] = Object.values(conversations)
16+
.map((x) => x.content.map((x) => x.message))
17+
.flat();

example/download-conversations.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
wget https://github.com/alexa/Topical-Chat/raw/refs/heads/master/conversations/train.json -O conversations.json

example/indexConversations.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { messages } from "./conversations.ts";
2+
3+
for (let i = 0; i < messages.length; i++) {
4+
const message = messages[i];
5+
await fetch(`http://localhost:3000/index/${i}`, {
6+
method: "post",
7+
body: message,
8+
});
9+
}

example/search.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { messages } from "./conversations.ts";
2+
3+
const query = Deno.args.join(" ");
4+
5+
const resp = await fetch("http://localhost:3000/search?limit=20", {
6+
method: "post",
7+
body: query,
8+
});
9+
10+
const results: { id: string; score: number }[] = await resp.json();
11+
12+
console.log(
13+
results
14+
.map((x) => ({
15+
message: messages[parseInt(x.id)],
16+
score: x.score,
17+
}))
18+
.reverse()
19+
);

0 commit comments

Comments
 (0)