src/pqc_rag_signing/adapters/base.py
1.1 KB · 39 lines · python Raw
1 """Abstract vector store adapter interface."""
2
3 from __future__ import annotations
4
5 from abc import ABC, abstractmethod
6 from typing import Iterable
7
8 from pqc_rag_signing.chunk import SignedChunk
9
10
11 class VectorStoreAdapter(ABC):
12 """Base class for vector DB integrations.
13
14 Implementations must preserve the full SignedChunk envelope (not just
15 text + embedding) so verification is possible at retrieval time.
16 Most vector DBs support arbitrary metadata - store ``chunk.to_dict()``
17 as metadata alongside the embedding.
18 """
19
20 @abstractmethod
21 def upsert(
22 self,
23 chunks: Iterable[SignedChunk],
24 embeddings: list[list[float]],
25 ) -> None:
26 """Store signed chunks with their embeddings."""
27
28 @abstractmethod
29 def query(self, embedding: list[float], top_k: int = 5) -> list[SignedChunk]:
30 """Retrieve top-k chunks for a query embedding.
31
32 Returns SignedChunks with full envelope intact so verification works
33 downstream.
34 """
35
36 @abstractmethod
37 def count(self) -> int:
38 """Return total number of chunks stored."""
39