Skip to content

Commit

Permalink
add keyword test
Browse files Browse the repository at this point in the history
  • Loading branch information
jlonge4 committed Mar 30, 2024
1 parent 6760063 commit 01cf28a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def __init__(
document_store: PgvectorDocumentStore,
filters: Optional[Dict[str, Any]] = None,
top_k: int = 10,
language: str = "english",
):
"""
:param document_store: An instance of `PgvectorDocumentStore}.
Expand All @@ -74,6 +75,7 @@ def __init__(
self.document_store = document_store
self.filters = filters or {}
self.top_k = top_k
self.language = language

def to_dict(self) -> Dict[str, Any]:
"""
Expand All @@ -87,6 +89,7 @@ def to_dict(self) -> Dict[str, Any]:
filters=self.filters,
top_k=self.top_k,
document_store=self.document_store.to_dict(),
language=self.language,
)

@classmethod
Expand All @@ -109,6 +112,7 @@ def run(
user_query: str,
filters: Optional[Dict[str, Any]] = None,
top_k: Optional[int] = None,
language: Optional[str] = "english",
):
"""
Retrieve documents from the `PgvectorDocumentStore`, based on their embeddings.
Expand All @@ -121,10 +125,12 @@ def run(
"""
filters = filters or self.filters
top_k = top_k or self.top_k
language = language or self.language

docs = self.document_store._keyword_retrieval(
user_query=user_query,
filters=filters,
top_k=top_k,
language=language,
)
return {"documents": docs}
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ def _keyword_retrieval(
ts_rank_cd(to_tsvector(%(language)s, content), query) DESC) AS rank
FROM {table_name}, plainto_tsquery(%(language)s, %(query)s) query
WHERE to_tsvector(%(language)s, content) @@ query"""
).format(table_name=Identifier(self.table_name), language=language)
).format(table_name=Identifier(self.table_name), language=language, query=user_query)

sql_where_clause = SQL("")
params = ()
Expand Down

0 comments on commit 01cf28a

Please sign in to comment.