@@ -20,15 +20,13 @@ def create(
20
20
embedding_generator = embedding_generator
21
21
)
22
22
23
- def _build_eval_script (self , query , query_embedding ):
23
+ def _build_optic_query (self , query , query_embedding ):
24
24
words = []
25
25
for word in query .split ():
26
26
if len (word ) > 2 :
27
27
words .append (word .lower ().replace ("?" , "" ))
28
28
29
29
return """
30
- const op = require('/MarkLogic/optic');
31
-
32
30
op.fromSearchDocs(
33
31
cts.andQuery([cts.wordQuery({}), cts.collectionQuery('events')]),
34
32
null,
@@ -58,19 +56,18 @@ def _build_eval_script(self, query, query_embedding):
58
56
.select(['uri', 'transcript', 'hybridScore'])
59
57
.orderBy(op.desc(op.col('hybridScore')))
60
58
.limit(10)
61
- .result()
62
59
""" .format (
63
60
words ,
64
61
query_embedding
65
62
)
66
63
67
64
def _get_relevant_documents (self , query : str ) -> List [Document ]:
68
65
query_embedding = self .embedding_generator .embed_query (query )
69
- eval_script = self ._build_eval_script (query , query_embedding )
70
- optic_rows = self .client .eval ( javascript = eval_script )
71
- print ( optic_rows [ 1 ]. keys ())
66
+ eval_script = self ._build_optic_query (query , query_embedding )
67
+ optic_response = self .client .rows . query ( eval_script , format = "json" )
68
+ optic_rows = optic_response [ "rows" ]
72
69
73
70
print (f"Count of MarkLogic chunks sent to the LLM: { len (optic_rows )} " )
74
71
for optic_row in optic_rows :
75
72
print (f"URI: { optic_row ['uri' ]} " )
76
- return map (lambda optic_row : Document (page_content = optic_row ["transcript" ]), optic_rows )
73
+ return map (lambda optic_row : Document (page_content = optic_row ["transcript" ][ "value" ] ), optic_rows )
0 commit comments