Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ColbertVectorStore as_retriever() #611

Merged
merged 1 commit into from
Jul 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from typing import Any, Iterable, List, Optional, Tuple, Type, TypeVar

from langchain_core.documents import Document
from langchain_core.retrievers import BaseRetriever
from langchain_core.vectorstores import VectorStore
from langchain_core.vectorstores import VectorStore, VectorStoreRetriever
from ragstack_colbert import Chunk
from ragstack_colbert import ColbertVectorStore as RagstackColbertVectorStore
from ragstack_colbert.base_database import BaseDatabase as ColbertBaseDatabase
Expand All @@ -13,8 +12,6 @@
from ragstack_colbert.base_vector_store import BaseVectorStore as ColbertBaseVectorStore
from typing_extensions import override

from .colbert_retriever import ColbertRetriever

CVS = TypeVar("CVS", bound="ColbertVectorStore")


Expand Down Expand Up @@ -282,8 +279,11 @@ async def afrom_texts(
return instance

@override
def as_retriever(self, k: Optional[int] = 5, **kwargs: Any) -> BaseRetriever:
def as_retriever(self, k: Optional[int] = 5, **kwargs: Any) -> VectorStoreRetriever:
"""Return a VectorStoreRetriever initialized from this VectorStore."""
return ColbertRetriever(
retriever=self._vector_store.as_retriever(), k=k, **kwargs
)
search_kwargs = kwargs.pop("search_kwargs", {})
search_kwargs["k"] = k
search_type = kwargs.get("search_type", "similarity")
if search_type != "similarity":
raise ValueError(f"Unsupported search type: {search_type}")
return super().as_retriever(search_kwargs=search_kwargs, **kwargs)