From 0a6b7793e982d4c59f3c6ffb947dfe28ca709cdc Mon Sep 17 00:00:00 2001 From: Gustaf Rydholm Date: Fri, 5 Apr 2024 00:42:19 +0200 Subject: Rename --- rag/db/embeddings.py | 23 +++++++++++++++++++++++ rag/db/vector.py | 23 ----------------------- 2 files changed, 23 insertions(+), 23 deletions(-) create mode 100644 rag/db/embeddings.py delete mode 100644 rag/db/vector.py (limited to 'rag/db') diff --git a/rag/db/embeddings.py b/rag/db/embeddings.py new file mode 100644 index 0000000..f9d0735 --- /dev/null +++ b/rag/db/embeddings.py @@ -0,0 +1,23 @@ +import os +from typing import Tuple + +import faiss +import numpy as np + + +# TODO: inner product distance metric? +class Embeddings: + def __init__(self): + self.dim = os.environ["EMBEDDING_DIM"] + self.index = faiss.IndexFlatL2(self.dim) + # TODO: load from file + + def add(self, embeddings: np.ndarray): + # TODO: save to file + self.index.add(embeddings) + + def search( + self, query: np.ndarray, neighbors: int = 4 + ) -> Tuple[np.ndarray, np.ndarray]: + score, indices = self.index.search(query, neighbors) + return score, indices diff --git a/rag/db/vector.py b/rag/db/vector.py deleted file mode 100644 index f229ba7..0000000 --- a/rag/db/vector.py +++ /dev/null @@ -1,23 +0,0 @@ -from typing import Tuple -import faiss -import numpy as np - -# TODO: read from .env -EMBEDDING_DIM = 1024 - - -# TODO: inner product distance metric? -class VectorStore: - def __init__(self): - self.index = faiss.IndexFlatL2(EMBEDDING_DIM) - # TODO: load from file - - def add(self, embeddings: np.ndarray): - # TODO: save to file - self.index.add(embeddings) - - def search( - self, query: np.ndarray, neighbors: int = 4 - ) -> Tuple[np.ndarray, np.ndarray]: - score, indices = self.index.search(query, neighbors) - return score, indices -- cgit v1.2.3-70-g09d2