File tree Expand file tree Collapse file tree 6 files changed +80
-0
lines changed
Expand file tree Collapse file tree 6 files changed +80
-0
lines changed Original file line number Diff line number Diff line change 22model
33ort
44
5+ example /conversations.json
6+
57# pixi environments
68.pixi
79* .egg-info
Original file line number Diff line number Diff line change @@ -44,6 +44,38 @@ The endpoint will return a list of items with their ID and the similarity score
4444You can optionally add a ` limit ` query parameter which will set a limit on how many items are
4545returned, 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
4981The service is easily deployed, along with Qdrant, using docker compose:
Original file line number Diff line number Diff line change 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 ( ) ;
Original file line number Diff line number Diff line change 1+ wget https://github.com/alexa/Topical-Chat/raw/refs/heads/master/conversations/train.json -O conversations.json
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ ) ;
You can’t perform that action at this time.
0 commit comments