Skip to content

Commit 32aea64

Browse files
authored
Merge pull request #27 from BillFarber/task/changeEvalToRows
Now uses the /v1/rows endpoint for vector functions instead of /v1/eval.
2 parents edf6796 + 2595482 commit 32aea64

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

rag-langchain-python/vector_query_retriever.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,13 @@ def create(
2020
embedding_generator=embedding_generator
2121
)
2222

23-
def _build_eval_script(self, query, query_embedding):
23+
def _build_optic_query(self, query, query_embedding):
2424
words = []
2525
for word in query.split():
2626
if len(word) > 2:
2727
words.append(word.lower().replace("?", ""))
2828

2929
return """
30-
const op = require('/MarkLogic/optic');
31-
3230
op.fromSearchDocs(
3331
cts.andQuery([cts.wordQuery({}), cts.collectionQuery('events')]),
3432
null,
@@ -58,19 +56,18 @@ def _build_eval_script(self, query, query_embedding):
5856
.select(['uri', 'transcript', 'hybridScore'])
5957
.orderBy(op.desc(op.col('hybridScore')))
6058
.limit(10)
61-
.result()
6259
""".format(
6360
words,
6461
query_embedding
6562
)
6663

6764
def _get_relevant_documents(self, query: str) -> List[Document]:
6865
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"]
7269

7370
print(f"Count of MarkLogic chunks sent to the LLM: {len(optic_rows)}")
7471
for optic_row in optic_rows:
7572
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

Comments
 (0)