diff options
author | Gustaf Rydholm <gustaf.rydholm@gmail.com> | 2024-04-05 00:42:02 +0200 |
---|---|---|
committer | Gustaf Rydholm <gustaf.rydholm@gmail.com> | 2024-04-05 00:42:02 +0200 |
commit | 1cf0a401054c3e3ebde60bfd73ad15e39bc531e6 (patch) | |
tree | 633314ef342c35213cfa01607dd3c98e77b7cdd2 /rag/llm | |
parent | 633f180eb0ccdc4772d5d705873cef1e33507976 (diff) |
Rename llm
Diffstat (limited to 'rag/llm')
-rw-r--r-- | rag/llm/__init__.py | 0 | ||||
-rw-r--r-- | rag/llm/encoder.py | 23 | ||||
-rw-r--r-- | rag/llm/generator.py | 0 |
3 files changed, 23 insertions, 0 deletions
diff --git a/rag/llm/__init__.py b/rag/llm/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/rag/llm/__init__.py diff --git a/rag/llm/encoder.py b/rag/llm/encoder.py new file mode 100644 index 0000000..d5e0566 --- /dev/null +++ b/rag/llm/encoder.py @@ -0,0 +1,23 @@ +import os +from typing import List + +import numpy as np +import ollama + + +class Encoder: + def __init__(self) -> None: + self.model = os.environ["ENCODER_MODEL"] + self.query_prompt = "Represent this sentence for searching relevant passages: " + + def __encode(self, prompt: str) -> np.ndarray: + x = ollama.embeddings(model=ENCODER_MODEL, prompt=prompt) + x = np.array([x["embedding"]]).astype("float32") + return x + + def encode(self, doc: List[str]) -> List[np.ndarray]: + return [self.__encode(chunk) for chunk in doc] + + def query(self, query: str) -> np.ndarray: + query = self.query_prompt + query + return self.__encode(query) diff --git a/rag/llm/generator.py b/rag/llm/generator.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/rag/llm/generator.py |