@@ -8,23 +8,39 @@ use async_trait::async_trait;
8
8
use colored:: Colorize ;
9
9
use glob:: glob;
10
10
11
- use super :: { Document , Embeddings , VectorStore } ;
11
+ use super :: { Configuration , Document , Embeddings , VectorStore } ;
12
12
use crate :: agent:: { generator:: Client , rag:: metrics} ;
13
13
14
14
// TODO: integrate other more efficient vector databases.
15
15
16
16
pub struct NaiveVectorStore {
17
+ config : Configuration ,
17
18
embedder : Box < dyn Client > ,
18
19
documents : HashMap < String , Document > ,
19
20
embeddings : HashMap < String , Embeddings > ,
20
21
}
21
22
22
- impl NaiveVectorStore {
23
- // TODO: add persistency
24
- pub async fn from_indexed_path ( generator : Box < dyn Client > , path : & str ) -> Result < Self > {
25
- let path = std:: fs:: canonicalize ( path) ?. display ( ) . to_string ( ) ;
23
+ #[ async_trait]
24
+ impl VectorStore for NaiveVectorStore {
25
+ #[ allow( clippy:: borrowed_box) ]
26
+ async fn new ( embedder : Box < dyn Client > , config : Configuration ) -> Result < Self >
27
+ where
28
+ Self : Sized ,
29
+ {
30
+ // TODO: add persistency
31
+ let documents = HashMap :: new ( ) ;
32
+ let embeddings = HashMap :: new ( ) ;
33
+ let mut store = Self {
34
+ config,
35
+ documents,
36
+ embeddings,
37
+ embedder,
38
+ } ;
39
+
40
+ let path = std:: fs:: canonicalize ( & store. config . path ) ?
41
+ . display ( )
42
+ . to_string ( ) ;
26
43
let expr = format ! ( "{}/**/*.txt" , path) ;
27
- let mut store = NaiveVectorStore :: new_with_generator ( generator) ?;
28
44
29
45
for path in ( glob ( & expr) ?) . flatten ( ) {
30
46
let doc_name = path. display ( ) ;
@@ -39,24 +55,6 @@ impl NaiveVectorStore {
39
55
40
56
Ok ( store)
41
57
}
42
- }
43
-
44
- #[ async_trait]
45
- impl VectorStore for NaiveVectorStore {
46
- #[ allow( clippy:: borrowed_box) ]
47
- fn new_with_generator ( embedder : Box < dyn Client > ) -> Result < Self >
48
- where
49
- Self : Sized ,
50
- {
51
- let documents = HashMap :: new ( ) ;
52
- let embeddings = HashMap :: new ( ) ;
53
-
54
- Ok ( Self {
55
- documents,
56
- embeddings,
57
- embedder,
58
- } )
59
- }
60
58
61
59
async fn add ( & mut self , document : Document ) -> Result < ( ) > {
62
60
if self . documents . contains_key ( & document. name ) {
0 commit comments