Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Memri
plugins
Semantic Search
Commits
8896d353
Commit
8896d353
authored
2 years ago
by
Alp Deniz Ogut
Browse files
Options
Download
Email Patches
Plain Diff
Update demo
parent
1bce2f4e
Pipeline
#14104
passed with stages
in 6 minutes and 20 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tools/demo.py
+22
-50
tools/demo.py
with
22 additions
and
50 deletions
+22
-50
tools/demo.py
+
22
-
50
View file @
8896d353
import
json
from
pathlib
import
Path
from
typing
import
List
from
pymemri.data.schema
import
Tweet
import
requests
from
pymemri.pod.client
import
PodClient
from
rich
import
print
from
rich.panel
import
Panel
from
rich.prompt
import
Confirm
,
Prompt
from
rich.rule
import
Rule
from
semantic_search.plugin
import
SemanticSearchPlugin
def
get_tweets
()
->
List
[
Tweet
]:
with
open
(
TWEET_FILE
,
"r"
)
as
f
:
tweets_json
=
json
.
load
(
f
)
return
[
Tweet
.
from_json
(
t
)
for
t
in
tweets_json
]
def
print_tweet
(
tweet
):
print
(
Panel
(
tweet
.
message
))
ASSETS_DIR
=
Path
(
__file__
).
parent
.
parent
/
"tests"
/
"test_assets"
TWEET_FILE
=
ASSETS_DIR
/
"tweets.json"
def
setup_plugin
():
tweets
=
get_tweets
()
client
=
PodClient
()
client
.
add_to_schema
(
Tweet
)
client
.
bulk_action
(
create_items
=
tweets
)
plugin
=
SemanticSearchPlugin
(
client
=
client
)
plugin
.
add_to_index
(
tweets
)
return
plugin
def
main
():
plugin
=
setup_plugin
()
go_again
=
True
while
go_again
:
query
=
Prompt
.
ask
(
"enter your search query"
)
results
=
plugin
.
search_top_k
(
query
)
for
result
in
results
:
print_tweet
(
result
)
print
(
Rule
())
go_again
=
Confirm
.
ask
(
"Go again?"
)
c
=
PodClient
(
url
=
'https://dev.backend.memri.io'
)
pck
=
{
"url"
:
"https://dev.backend.memri.io"
,
"owner_key"
:
c
.
owner_key
,
"database_key"
:
c
.
database_key
}
payload
=
{
'pod_client_kwargs'
:
pck
,
'texts'
:
[
'hello this is a warm welcome'
,
'The world as we observe is just a collective illusion of our senses. Additionally, we have not yet looked beyond the electromagnetic domain'
],
'ids'
:
[
'Simple greeting'
,
'Philosophical questioning'
]
}
response
=
requests
.
post
(
"https://semantic-search.dev.backend.memri.io/index_texts?index_name=question"
,
json
=
payload
)
print
(
response
.
content
)
query
=
'philosophy'
print
(
f
"Querying '
{
query
}
'..."
)
response
=
requests
.
post
(
f
"https://semantic-search.dev.backend.memri.io/search_top_k?index_name=question&query=
{
query
}
&top_k=1"
,
json
=
payload
)
print
(
response
.
content
)
query
=
'greeting'
print
(
f
"Querying '
{
query
}
'..."
)
response
=
requests
.
post
(
f
"https://semantic-search.dev.backend.memri.io/search_top_k?index_name=question&query=
{
query
}
&top_k=1"
,
json
=
payload
)
print
(
response
.
content
)
if
__name__
==
"__main__"
:
main
()
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Snippets