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
// show feature flags in the generated documentation
// https://doc.rust-lang.org/rustdoc/unstable-features.html#extensions-to-the-doc-attribute
pub use prompt;
pub use *;
pub use swiftide_agents as agents;
/// Common traits for common behaviour, re-exported from indexing and query
/// Abstractions for chat completions and LLM interactions.
pub use chat_completion;
/// Integrations with various platforms and external services.
/// This module serves as the main entry point for indexing in Swiftide.
///
/// The indexing system in Swiftide is designed to handle the asynchronous processing of large
/// volumes of data, including loading, transforming, and storing data chunks.
pub use *;
/// # Querying pipelines
///
/// Swiftide allows you to define sophisticated query pipelines.
///
/// Consider the following code that uses Swiftide to load some markdown text, chunk it, embed it,
/// and store it in a Qdrant index:
///
/// ```no_run
/// use swiftide::{
/// indexing::{
/// self,
/// loaders::FileLoader,
/// transformers::{ChunkMarkdown, Embed, MetadataQAText},
/// },
/// integrations::{self, qdrant::Qdrant},
/// integrations::openai::OpenAI,
/// query::{self, answers, query_transformers, response_transformers},
/// };
///
/// async fn index() -> Result<(), Box<dyn std::error::Error>> {
/// let openai_client = OpenAI::builder()
/// .default_embed_model("text-embedding-3-large")
/// .default_prompt_model("gpt-4o")
/// .build()?;
///
/// let qdrant = Qdrant::builder()
/// .batch_size(50)
/// .vector_size(3072)
/// .collection_name("swiftide-examples")
/// .build()?;
///
/// indexing::Pipeline::from_loader(FileLoader::new("README.md"))
/// .then_chunk(ChunkMarkdown::from_chunk_range(10..2048))
/// .then(MetadataQAText::new(openai_client.clone()))
/// .then_in_batch(Embed::new(openai_client.clone()).with_batch_size(10))
/// .then_store_with(qdrant.clone())
/// .run()
/// .await?;
///
/// Ok(())
/// }
/// ```
///
/// We could then define a query pipeline that uses the Qdrant index to answer questions:
///
/// ```no_run
/// # use swiftide::{
/// # indexing::{
/// # self,
/// # loaders::FileLoader,
/// # transformers::{ChunkMarkdown, Embed, MetadataQAText},
/// # },
/// # integrations::{self, qdrant::Qdrant},
/// # query::{self, answers, query_transformers, response_transformers},
/// # integrations::openai::OpenAI,
/// # };
/// # async fn query() -> Result<(), Box<dyn std::error::Error>> {
/// # let openai_client = OpenAI::builder()
/// # .default_embed_model("text-embedding-3-large")
/// # .default_prompt_model("gpt-4o")
/// # .build()?;
/// # let qdrant = Qdrant::builder()
/// # .batch_size(50)
/// # .vector_size(3072)
/// # .collection_name("swiftide-examples")
/// # .build()?;
/// // By default the search strategy is SimilaritySingleEmbedding
/// // which takes the latest query, embeds it, and does a similarity search
/// let pipeline = query::Pipeline::default()
/// .then_transform_query(query_transformers::GenerateSubquestions::from_client(
/// openai_client.clone(),
/// ))
/// .then_transform_query(query_transformers::Embed::from_client(
/// openai_client.clone(),
/// ))
/// .then_retrieve(qdrant.clone())
/// .then_transform_response(response_transformers::Summary::from_client(
/// openai_client.clone(),
/// ))
/// .then_answer(answers::Simple::from_client(openai_client.clone()));
///
/// let result = pipeline
/// .query("What is swiftide? Please provide an elaborate explanation")
/// .await?;
///
/// println!("{:?}", result.answer());
/// # Ok(())
/// # }
/// ```
///
/// By using a query pipeline to transform queries, we can improve the quality of the answers we get
/// from our index. In this example, we used an LLM to generate subquestions, embedding those and
/// then using them to search the index. Finally, we summarize the results and combine them together
/// into a single answer.
pub use swiftide_langfuse as langfuse;
/// Re-exports for macros