Skip to content

Commit

Permalink
Add similarity search with score (#37)
Browse files Browse the repository at this point in the history
* Hotfix

* Lint

* Add similarity_search_with_score

* Clean up codebase
  • Loading branch information
Enias Cailliau committed Apr 17, 2023
1 parent c659ae2 commit 3eb8d52
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/steamship_langchain/vectorstores/steamship_vector_store.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import uuid
from itertools import zip_longest
from typing import Any, Iterable, List, Optional
from typing import Any, Iterable, List, Optional, Tuple

from langchain.docstore.document import Document
from langchain.text_splitter import TextSplitter
Expand Down Expand Up @@ -161,6 +161,15 @@ def similarity_search(self, query: str, k: int = 4, **kwargs: Any) -> List[Docum
for item in search_results.output.items
]

def similarity_search_with_score(self, query: str, k: int = 4) -> List[Tuple[Document, float]]:
search_results = self.index.search(query, k=k)
search_results.wait()
docs = []
for item in search_results.output.items:
doc = Document(page_content=item.tag.text, metadata=item.tag.value)
docs.append((doc, item.score))
return docs

def similarity_search_by_vector(
self, embedding: List[float], k: int = 4, **kwargs: Any
) -> List[Document]:
Expand Down

0 comments on commit 3eb8d52

Please sign in to comment.