File tree Expand file tree Collapse file tree 3 files changed +108
-0
lines changed Expand file tree Collapse file tree 3 files changed +108
-0
lines changed Original file line number Diff line number Diff line change @@ -198,6 +198,15 @@ client.query.aggs(
198198)
199199```
200200
201+ #### Explore
202+ ``` ruby
203+ client.query.explore(
204+ fields: ' className' ,
205+ near_text: " { concepts: [\" science\" ] }" ,
206+ limit: " 1"
207+ )
208+ ```
209+
201210### Classification
202211``` ruby
203212client.classifications.create(
Original file line number Diff line number Diff line change @@ -58,8 +58,63 @@ def aggs(
5858 raise Weaviate ::Error . new ( error . response . data . aggregate . errors . messages . to_h )
5959 end
6060
61+ def explore (
62+ fields :,
63+ after : nil ,
64+ limit : nil ,
65+ offset : nil ,
66+ sort : nil ,
67+ where : nil ,
68+ near_text : nil ,
69+ near_vector : nil ,
70+ near_object : nil
71+ )
72+ response = client . graphql . execute (
73+ explore_query (
74+ fields : fields ,
75+ near_text : near_text ,
76+ near_vector : near_vector ,
77+ near_object : near_object
78+ ) ,
79+ after : after ,
80+ limit : limit ,
81+ offset : offset
82+ )
83+ response . data . explore
84+ rescue Graphlient ::Errors ::ExecutionError => error
85+ raise Weaviate ::Error . new ( error . to_s )
86+ end
87+
6188 private
6289
90+ def explore_query (
91+ fields :,
92+ where : nil ,
93+ near_text : nil ,
94+ near_vector : nil ,
95+ near_object : nil ,
96+ sort : nil
97+ )
98+ client . graphql . parse <<~GRAPHQL
99+ query(
100+ $limit: Int,
101+ $offset: Int
102+ ) {
103+ Explore (
104+ limit: $limit,
105+ offset: $offset,
106+ #{ near_text . present? ? "nearText: #{ near_text } " : "" } ,
107+ #{ near_vector . present? ? "nearVector: #{ near_vector } " : "" } ,
108+ #{ near_object . present? ? "nearObject: #{ near_object } " : "" }
109+ #{ where . present? ? "where: #{ where } " : "" } ,
110+ #{ sort . present? ? "sort: #{ sort } " : "" }
111+ ) {
112+ #{ fields }
113+ }
114+ }
115+ GRAPHQL
116+ end
117+
63118 def get_query (
64119 class_name :,
65120 fields :,
Original file line number Diff line number Diff line change 105105 expect ( data . first . question ) . to eq ( "In 1953 Watson & Crick built a model of the molecular structure of this, the gene-carrying substance" )
106106 end
107107 end
108+
109+ describe "#explore" do
110+ let ( :response ) {
111+ double (
112+ data : double (
113+ explore : [ double ( certainty : "0.9999" , class_name : "Question" ) ]
114+ )
115+ )
116+ }
117+
118+ let ( :graphql_query ) {
119+ <<-GRAPHQL
120+ query {
121+ Explore(
122+ limit: 1
123+ nearText: { concepts: ["biology"] }
124+ ) {
125+ certainty
126+ className
127+ }
128+ }
129+ GRAPHQL
130+ }
131+
132+ before do
133+ allow_any_instance_of ( Graphlient ::Client ) . to receive ( :parse )
134+ . and_return ( graphql_query )
135+
136+ allow_any_instance_of ( Graphlient ::Client ) . to receive ( :execute )
137+ . and_return ( response )
138+ end
139+
140+ it "returns the query" do
141+ response = query . explore (
142+ fields : "certainty className" ,
143+ near_text : "{ concepts: [\" biology\" ] }" ,
144+ limit : "1"
145+ )
146+
147+ expect ( response . count ) . to eq ( 1 )
148+ expect ( response . first . certainty ) . to eq ( "0.9999" )
149+ expect ( response . first . class_name ) . to eq ( "Question" )
150+ end
151+ end
108152end
You can’t perform that action at this time.
0 commit comments