File size: 7,158 Bytes
692f5d1
 
 
c415e05
bfb6e70
c415e05
 
 
 
 
 
 
 
 
 
 
bfb6e70
c415e05
bfb6e70
c415e05
bfb6e70
a4a76e6
 
c415e05
bfb6e70
c415e05
bfb6e70
c415e05
bfb6e70
c415e05
bfb6e70
c415e05
 
 
bfb6e70
c415e05
 
 
 
 
 
 
 
0b084fa
c415e05
 
a4a76e6
 
 
 
 
126ef7b
a4a76e6
 
 
c415e05
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a4a76e6
c415e05
 
 
 
 
 
a4a76e6
c415e05
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a4a76e6
c415e05
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0b084fa
c415e05
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a4a76e6
c415e05
 
 
 
 
 
a4a76e6
c415e05
 
 
 
bfb6e70
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
---
license: mit
---
# Table of Contents

* [run](#run)
* [ChromaDBFlow](#ChromaDBFlow)
  * [ChromaDBFlow](#ChromaDBFlow.ChromaDBFlow)
    * [instantiate\_from\_config](#ChromaDBFlow.ChromaDBFlow.instantiate_from_config)
    * [run](#ChromaDBFlow.ChromaDBFlow.run)
* [VectorStoreFlow](#VectorStoreFlow)
  * [VectorStoreFlow](#VectorStoreFlow.VectorStoreFlow)
    * [instantiate\_from\_config](#VectorStoreFlow.VectorStoreFlow.instantiate_from_config)
    * [package\_documents](#VectorStoreFlow.VectorStoreFlow.package_documents)
    * [run](#VectorStoreFlow.VectorStoreFlow.run)
* [\_\_init\_\_](#__init__)

<a id="run"></a>

# run

A simple script to run a Flow that can be used for development and debugging.

<a id="ChromaDBFlow"></a>

# ChromaDBFlow

<a id="ChromaDBFlow.ChromaDBFlow"></a>

## ChromaDBFlow Objects

```python
class ChromaDBFlow(AtomicFlow)
```

A flow that uses the ChromaDB model to write and read memories stored in a database

*Configuration Parameters*:

- `name` (str): The name of the flow. Default: "chroma_db"
- `description` (str): A description of the flow. This description is used to generate the help message of the flow. 
Default: "ChromaDB is a document store that uses vector embeddings to store and retrieve documents."
- `backend` (Dict[str, Any]): The configuration of the backend which is used to fetch api keys. Default: LiteLLMBackend with the
default parameters of LiteLLMBackend (see aiflows.backends.LiteLLMBackend). Except for the following parameter whose default value is overwritten:
    - `api_infos` (List[Dict[str, Any]]): The list of api infos. Default: No default value, this parameter is required.
    - `model_name` (str): The name of the model. Default: "". In the current implementation, this parameter is not used.
- `similarity_search_kwargs` (Dict[str, Any]): The parameters to pass to the similarity search method of the ChromaDB. Default:
    - `k` (int): The number of documents to retrieve. Default: 2
    - `filter` (str): The filter to apply to the documents. Default: null
- `paths_to_data` (List[str]): The paths to the data to store in the database at instantiation. Default: []
- `chunk_size` (int): The size of the chunks to split the documents into. Default: 700
- `seperator` (str): The separator to use to split the documents. Default: "\n"
- `chunk_overlap` (int): The overlap between the chunks. Default: 0
- `persist_directory` (str): The directory to persist the database. Default: "./demo_db_dir"

- Other parameters are inherited from the default configuration of AtomicFlow (see AtomicFlow)

*Input Interface*:

- `operation` (str): The operation to perform. It can be "write" or "read".
- `content` (str or List[str]): The content to write or read. If operation is "write", it must be a string or a list of strings. If operation is "read", it must be a string.

*Output Interface*:

- `retrieved` (str or List[str]): The retrieved content. If operation is "write", it is an empty string. If operation is "read", it is a string or a list of strings.

**Arguments**:

- `backend` (`LiteLLMBackend`): The backend of the flow (used to retrieve the API key)
- `\**kwargs`: Additional arguments to pass to the flow.

<a id="ChromaDBFlow.ChromaDBFlow.instantiate_from_config"></a>

#### instantiate\_from\_config

```python
@classmethod
def instantiate_from_config(cls, config)
```

This method instantiates the flow from a configuration file

**Arguments**:

- `config` (`Dict[str, Any]`): The configuration of the flow.

**Returns**:

`ChromaDBFlow`: The instantiated flow.

<a id="ChromaDBFlow.ChromaDBFlow.run"></a>

#### run

```python
def run(input_message: FlowMessage)
```

This method runs the flow. It runs the ChromaDBFlow. It either writes or reads memories from the database.

**Arguments**:

- `input_message` (`FlowMessage`): The input message of the flow.

<a id="VectorStoreFlow"></a>

# VectorStoreFlow

<a id="VectorStoreFlow.VectorStoreFlow"></a>

## VectorStoreFlow Objects

```python
class VectorStoreFlow(AtomicFlow)
```

A flow that uses the VectorStore model to write and read memories stored in a database (see VectorStoreFlow.yaml for the default configuration)

*Configuration Parameters*:

- `name` (str): The name of the flow. Default: "VecotrStoreFlow"
- `description` (str): A description of the flow. This description is used to generate the help message of the flow.
Default: "VectorStoreFlow"
- `backend` (Dict[str, Any]): The configuration of the backend which is used to fetch api keys. Default: LiteLLMBackend with the
default parameters of LiteLLMBackend (see flows.backends.LiteLLMBackend). Except for the following parameter whose default value is overwritten:
    - `api_infos` (List[Dict[str, Any]]): The list of api infos. Default: No default value, this parameter is required.
    - `model_name` (str): The name of the model. Default: "". In the current implementation, this parameter is not used.
- `type` (str): The type of the vector store. It can be "chroma" or "faiss". Default: "chroma"
- `embedding_size` (int): The size of the embeddings (only for faiss). Default: 1536
- `retriever_config` (Dict[str, Any]): The configuration of the retriever. Default: empty dictionary
- Other parameters are inherited from the default configuration of AtomicFlow (see AtomicFlow)

*Input Interface*:

- `operation` (str): The operation to perform. It can be "write" or "read".
- `content` (str or List[str]): The content to write or read. If operation is "write", it must be a string or a list of strings. If operation is "read", it must be a string.

*Output Interface*:

- `retrieved` (str or List[str]): The retrieved content. If operation is "write", it is an empty string. If operation is "read", it is a string or a list of strings.

**Arguments**:

- `backend` (`LiteLLMBackend`): The backend of the flow (used to retrieve the API key)
- `vector_db` (`VectorStoreRetriever`): The vector store retriever
- `type` (`str`): The type of the vector store
- `\**kwargs`: Additional arguments to pass to the flow. See :class:`aiflows.base_flows.AtomicFlow` for more details.

<a id="VectorStoreFlow.VectorStoreFlow.instantiate_from_config"></a>

#### instantiate\_from\_config

```python
@classmethod
def instantiate_from_config(cls, config: Dict[str, Any])
```

This method instantiates the flow from a configuration file

**Arguments**:

- `config` (`Dict[str, Any]`): The configuration of the flow.

**Returns**:

`VectorStoreFlow`: The instantiated flow.

<a id="VectorStoreFlow.VectorStoreFlow.package_documents"></a>

#### package\_documents

```python
@staticmethod
def package_documents(documents: List[str]) -> List[Document]
```

This method packages the documents in a list of Documents.

**Arguments**:

- `documents` (`List[str]`): The documents to package.

**Returns**:

`List[Document]`: The packaged documents.

<a id="VectorStoreFlow.VectorStoreFlow.run"></a>

#### run

```python
def run(input_message: FlowMessage)
```

This method runs the flow. It either writes or reads memories from the database.

**Arguments**:

- `input_message` (`FlowMessage`): The input data of the flow.

<a id="__init__"></a>

# \_\_init\_\_