-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
65 lines (55 loc) · 1.16 KB
/
Copy pathmodels.py
File metadata and controls
65 lines (55 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from dataclasses import dataclass
from pathlib import Path
from typing import Any
import numpy as np
@dataclass(slots=True)
class Document:
title: str
category: str
topic: str
content: str
metadata: dict[str, Any]
source_path: Path
@dataclass(slots=True)
class Chunk:
id: str
text: str
metadata: dict[str, Any]
@dataclass(slots=True)
class SearchResult:
chunk: Chunk
score: float
@dataclass(slots=True)
class EmbeddedChunk:
chunk: Chunk
embedding: np.ndarray
@dataclass(slots=True)
class Context:
text: str
sources: list[str]
chunk_count: int
@dataclass(slots=True)
class Prompt:
system: str
context: str
history: str
user: str
def build(self) -> str:
return (
f"{self.system}\n\n"
f"{self.context}\n\n"
f"{self.history}\n\n"
f"User:\n{self.user}"
)
@dataclass(slots=True)
class SearchRequest:
query: str
k: int = 5
filters: dict[str, Any] | None = None
@dataclass(slots=True)
class Intent:
categories: list[str]
@dataclass(slots=True)
class SearchResponse:
context: Context
results: list[SearchResult]