Skip to content

Commit cc8f761

Browse files
authored
Add ruff rules for future annotations (#621)
1 parent efa4b1b commit cc8f761

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+554
-401
lines changed

libs/colbert/ragstack_colbert/base_database.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
models.
66
"""
77

8+
from __future__ import annotations
9+
810
from abc import ABC, abstractmethod
9-
from typing import List, Tuple
11+
from typing import TYPE_CHECKING
1012

11-
from .objects import Chunk, Vector
13+
if TYPE_CHECKING:
14+
from .objects import Chunk, Vector
1215

1316

1417
class BaseDatabase(ABC):
@@ -24,7 +27,7 @@ class BaseDatabase(ABC):
2427
"""
2528

2629
@abstractmethod
27-
def add_chunks(self, chunks: List[Chunk]) -> List[Tuple[str, int]]:
30+
def add_chunks(self, chunks: list[Chunk]) -> list[tuple[str, int]]:
2831
"""Stores a list of embedded text chunks in the vector store.
2932
3033
Args:
@@ -35,7 +38,7 @@ def add_chunks(self, chunks: List[Chunk]) -> List[Tuple[str, int]]:
3538
"""
3639

3740
@abstractmethod
38-
def delete_chunks(self, doc_ids: List[str]) -> bool:
41+
def delete_chunks(self, doc_ids: list[str]) -> bool:
3942
"""Deletes chunks from the vector store based on their document id.
4043
4144
Args:
@@ -48,8 +51,8 @@ def delete_chunks(self, doc_ids: List[str]) -> bool:
4851

4952
@abstractmethod
5053
async def aadd_chunks(
51-
self, chunks: List[Chunk], concurrent_inserts: int = 100
52-
) -> List[Tuple[str, int]]:
54+
self, chunks: list[Chunk], concurrent_inserts: int = 100
55+
) -> list[tuple[str, int]]:
5356
"""Stores a list of embedded text chunks in the vector store.
5457
5558
Args:
@@ -63,7 +66,7 @@ async def aadd_chunks(
6366

6467
@abstractmethod
6568
async def adelete_chunks(
66-
self, doc_ids: List[str], concurrent_deletes: int = 100
69+
self, doc_ids: list[str], concurrent_deletes: int = 100
6770
) -> bool:
6871
"""Deletes chunks from the vector store based on their document id.
6972
@@ -78,7 +81,7 @@ async def adelete_chunks(
7881
"""
7982

8083
@abstractmethod
81-
async def search_relevant_chunks(self, vector: Vector, n: int) -> List[Chunk]:
84+
async def search_relevant_chunks(self, vector: Vector, n: int) -> list[Chunk]:
8285
"""Retrieves 'n' ANN results for an embedded token vector.
8386
8487
Returns:

libs/colbert/ragstack_colbert/base_embedding_model.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44
embeddings for text.
55
"""
66

7+
from __future__ import annotations
8+
79
from abc import ABC, abstractmethod
8-
from typing import List, Optional
10+
from typing import TYPE_CHECKING
911

10-
from .objects import Embedding
12+
if TYPE_CHECKING:
13+
from .objects import Embedding
1114

1215

1316
class BaseEmbeddingModel(ABC):
@@ -21,7 +24,7 @@ class BaseEmbeddingModel(ABC):
2124
"""
2225

2326
@abstractmethod
24-
def embed_texts(self, texts: List[str]) -> List[Embedding]:
27+
def embed_texts(self, texts: list[str]) -> list[Embedding]:
2528
"""Embeds a list of texts into their vector embedding representations.
2629
2730
Args:
@@ -36,7 +39,7 @@ def embed_query(
3639
self,
3740
query: str,
3841
full_length_search: bool = False,
39-
query_maxlen: Optional[int] = None,
42+
query_maxlen: int | None = None,
4043
) -> Embedding:
4144
"""Embeds a single query text into its vector representation.
4245

libs/colbert/ragstack_colbert/base_retriever.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
models.
66
"""
77

8+
from __future__ import annotations
9+
810
from abc import ABC, abstractmethod
9-
from typing import Any, List, Optional, Tuple
11+
from typing import TYPE_CHECKING, Any
1012

11-
from .objects import Chunk, Embedding
13+
if TYPE_CHECKING:
14+
from .objects import Chunk, Embedding
1215

1316

1417
class BaseRetriever(ABC):
@@ -24,10 +27,10 @@ class BaseRetriever(ABC):
2427
def embedding_search(
2528
self,
2629
query_embedding: Embedding,
27-
k: Optional[int] = None,
30+
k: int | None = None,
2831
include_embedding: bool = False,
2932
**kwargs: Any,
30-
) -> List[Tuple[Chunk, float]]:
33+
) -> list[tuple[Chunk, float]]:
3134
"""Search for relevant text chunks based on a query embedding.
3235
3336
Retrieves a list of text chunks relevant to a given query from the vector
@@ -53,10 +56,10 @@ def embedding_search(
5356
async def aembedding_search(
5457
self,
5558
query_embedding: Embedding,
56-
k: Optional[int] = None,
59+
k: int | None = None,
5760
include_embedding: bool = False,
5861
**kwargs: Any,
59-
) -> List[Tuple[Chunk, float]]:
62+
) -> list[tuple[Chunk, float]]:
6063
"""Search for relevant text chunks based on a query embedding.
6164
6265
Retrieves a list of text chunks relevant to a given query from the vector
@@ -82,11 +85,11 @@ async def aembedding_search(
8285
def text_search(
8386
self,
8487
query_text: str,
85-
k: Optional[int] = None,
86-
query_maxlen: Optional[int] = None,
88+
k: int | None = None,
89+
query_maxlen: int | None = None,
8790
include_embedding: bool = False,
8891
**kwargs: Any,
89-
) -> List[Tuple[Chunk, float]]:
92+
) -> list[tuple[Chunk, float]]:
9093
"""Search for relevant text chunks based on a query text.
9194
9295
Retrieves a list of text chunks relevant to a given query from the vector
@@ -113,11 +116,11 @@ def text_search(
113116
async def atext_search(
114117
self,
115118
query_text: str,
116-
k: Optional[int] = None,
117-
query_maxlen: Optional[int] = None,
119+
k: int | None = None,
120+
query_maxlen: int | None = None,
118121
include_embedding: bool = False,
119122
**kwargs: Any,
120-
) -> List[Tuple[Chunk, float]]:
123+
) -> list[tuple[Chunk, float]]:
121124
"""Search for relevant text chunks based on a query text.
122125
123126
Retrieves a list of text chunks relevant to a given query from the vector

libs/colbert/ragstack_colbert/base_vector_store.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55
and can be used to create a LangChain or LlamaIndex ColBERT vector store.
66
"""
77

8+
from __future__ import annotations
9+
810
from abc import ABC, abstractmethod
9-
from typing import List, Optional, Tuple
11+
from typing import TYPE_CHECKING
1012

11-
from .base_retriever import BaseRetriever
12-
from .objects import Chunk, Metadata
13+
if TYPE_CHECKING:
14+
from .base_retriever import BaseRetriever
15+
from .objects import Chunk, Metadata
1316

1417
# LlamaIndex Node (chunk) has ids, text, embedding, metadata
1518
# VectorStore.add(nodes: List[Node]) -> List[str](ids): embeds texts OUTside add # noqa: E501
@@ -37,7 +40,7 @@ class BaseVectorStore(ABC):
3740

3841
# handles LlamaIndex add
3942
@abstractmethod
40-
def add_chunks(self, chunks: List[Chunk]) -> List[Tuple[str, int]]:
43+
def add_chunks(self, chunks: list[Chunk]) -> list[tuple[str, int]]:
4144
"""Stores a list of embedded text chunks in the vector store.
4245
4346
Args:
@@ -51,10 +54,10 @@ def add_chunks(self, chunks: List[Chunk]) -> List[Tuple[str, int]]:
5154
@abstractmethod
5255
def add_texts(
5356
self,
54-
texts: List[str],
55-
metadatas: Optional[List[Metadata]],
56-
doc_id: Optional[str] = None,
57-
) -> List[Tuple[str, int]]:
57+
texts: list[str],
58+
metadatas: list[Metadata] | None,
59+
doc_id: str | None = None,
60+
) -> list[tuple[str, int]]:
5861
"""Adds text chunks to the vector store.
5962
6063
Embeds and stores a list of text chunks and optional metadata into the vector
@@ -73,7 +76,7 @@ def add_texts(
7376

7477
# handles LangChain and LlamaIndex delete
7578
@abstractmethod
76-
def delete_chunks(self, doc_ids: List[str]) -> bool:
79+
def delete_chunks(self, doc_ids: list[str]) -> bool:
7780
"""Deletes chunks from the vector store based on their document id.
7881
7982
Args:
@@ -87,8 +90,8 @@ def delete_chunks(self, doc_ids: List[str]) -> bool:
8790
# handles LlamaIndex add
8891
@abstractmethod
8992
async def aadd_chunks(
90-
self, chunks: List[Chunk], concurrent_inserts: int = 100
91-
) -> List[Tuple[str, int]]:
93+
self, chunks: list[Chunk], concurrent_inserts: int = 100
94+
) -> list[tuple[str, int]]:
9295
"""Stores a list of embedded text chunks in the vector store.
9396
9497
Args:
@@ -104,11 +107,11 @@ async def aadd_chunks(
104107
@abstractmethod
105108
async def aadd_texts(
106109
self,
107-
texts: List[str],
108-
metadatas: Optional[List[Metadata]],
109-
doc_id: Optional[str] = None,
110+
texts: list[str],
111+
metadatas: list[Metadata] | None,
112+
doc_id: str | None = None,
110113
concurrent_inserts: int = 100,
111-
) -> List[Tuple[str, int]]:
114+
) -> list[tuple[str, int]]:
112115
"""Adds text chunks to the vector store.
113116
114117
Embeds and stores a list of text chunks and optional metadata into the vector
@@ -130,7 +133,7 @@ async def aadd_texts(
130133
# handles LangChain and LlamaIndex delete
131134
@abstractmethod
132135
async def adelete_chunks(
133-
self, doc_ids: List[str], concurrent_deletes: int = 100
136+
self, doc_ids: list[str], concurrent_deletes: int = 100
134137
) -> bool:
135138
"""Deletes chunks from the vector store based on their document id.
136139

0 commit comments

Comments
 (0)