-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Separators: Implement html chunking strategy. #23
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,20 +34,12 @@ defmodule TextChunker.Strategies.RecursiveChunk.Separators do | |
"```\n\n", | ||
"\n\n___\n\n", | ||
"\n\n---\n\n", | ||
"\n\n***\n\n", | ||
"\n\n", | ||
"\n", | ||
" " | ||
] | ||
"\n\n***\n\n" | ||
] ++ empty_and_new_line_separators() | ||
end | ||
|
||
def get_separators(:plaintext) do | ||
[ | ||
"\n\n", | ||
"\n", | ||
" ", | ||
"" | ||
] | ||
empty_and_new_line_separators() ++ [""] | ||
end | ||
|
||
def get_separators(:elixir) do | ||
|
@@ -68,11 +60,8 @@ defmodule TextChunker.Strategies.RecursiveChunk.Separators do | |
" with ", | ||
" cond ", | ||
" case ", | ||
" if ", | ||
"\n\n", | ||
"\n", | ||
" " | ||
] | ||
" if " | ||
] ++ empty_and_new_line_separators() | ||
end | ||
|
||
def get_separators(:ruby) do | ||
|
@@ -90,11 +79,8 @@ defmodule TextChunker.Strategies.RecursiveChunk.Separators do | |
" for ", | ||
" do ", | ||
" begin ", | ||
" rescue ", | ||
"\n\n", | ||
"\n", | ||
" " | ||
] | ||
" rescue " | ||
] ++ empty_and_new_line_separators() | ||
end | ||
|
||
def get_separators(:php) do | ||
|
@@ -113,22 +99,16 @@ defmodule TextChunker.Strategies.RecursiveChunk.Separators do | |
" while ", | ||
" do ", | ||
" switch ", | ||
" case ", | ||
"\n\n", | ||
"\n", | ||
" " | ||
] | ||
" case " | ||
] ++ empty_and_new_line_separators() | ||
end | ||
|
||
def get_separators(:python) do | ||
[ | ||
"\nclass ", | ||
"\ndef ", | ||
"\n\tdef ", | ||
"\n\n", | ||
"\n", | ||
" " | ||
] | ||
"\n\tdef " | ||
] ++ empty_and_new_line_separators() | ||
end | ||
|
||
def get_separators(:vue) do | ||
|
@@ -157,14 +137,38 @@ defmodule TextChunker.Strategies.RecursiveChunk.Separators do | |
" while ", | ||
" switch ", | ||
" case ", | ||
" default ", | ||
"\n\n", | ||
"\n", | ||
" " | ||
] | ||
" default " | ||
] ++ empty_and_new_line_separators() | ||
end | ||
|
||
def get_separators(:html) do | ||
[ | ||
"<h1", | ||
"<h2", | ||
"<h3", | ||
"<h4", | ||
"<h5", | ||
"<h6", | ||
"<p", | ||
"<ul", | ||
"<ol", | ||
"<li", | ||
"<article", | ||
"<section", | ||
"<table" | ||
] ++ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm curious, why is it splitting on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was just being lazy and following the other examples (vue). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It just struck me while driving that this will also split on any HMTL tags that have attrs! So it makes way more sense than adding in the closing |
||
empty_and_new_line_separators() | ||
end | ||
|
||
def get_separators(:typescript), do: get_separators(:javascript) | ||
|
||
def get_separators(format) when format in @plaintext_formats, do: get_separators(:plaintext) | ||
|
||
defp empty_and_new_line_separators do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice |
||
[ | ||
"\n\n", | ||
"\n", | ||
" " | ||
] | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<h1>Elixir: A Powerful Language for Building Scalable Applications</h1> | ||
<p>Elixir is a dynamic, functional programming language designed for building scalable and maintainable applications. It runs on the Erlang Virtual Machine (VM), which is known for its robust concurrency and fault-tolerance capabilities. In this article, we'll explore the key features of Elixir and discuss different chunking approaches for Retrieval Augmented Generation (RAG).</p> | ||
|
||
<h2>Key Features of Elixir</h2> | ||
<ul> | ||
<li>Functional Programming: Elixir is built on the principles of functional programming, which emphasizes immutability, higher-order functions, and recursive algorithms.</li> | ||
<li>Concurrency and Scalability: Elixir leverages the power of the Erlang VM to provide lightweight processes and efficient message passing, enabling massive concurrency and scalability.</li> | ||
<li>Fault-Tolerance: With its actor-based concurrency model and support for supervisors, Elixir allows you to build fault-tolerant systems that can handle failures gracefully.</li> | ||
<li>Metaprogramming: Elixir provides powerful metaprogramming capabilities through macros, allowing you to extend the language and write expressive and reusable code.</li> | ||
</ul> | ||
|
||
<article> | ||
<h3>Chunking Approaches for Retrieval Augmented Generation</h3> | ||
<p>Retrieval Augmented Generation (RAG) is a technique that combines information retrieval with language generation to generate high-quality and informative text. Chunking, the process of breaking down text into smaller units, plays a crucial role in RAG. Let's explore different chunking approaches commonly used in Elixir:</p> | ||
<ol> | ||
<li>Sentence-based Chunking: This approach splits the text into individual sentences using punctuation markers such as periods, question marks, and exclamation points. Each sentence becomes a separate chunk, allowing for fine-grained retrieval and generation.</li> | ||
<li>Paragraph-based Chunking: With this approach, the text is divided into paragraphs based on the presence of newline characters or specific paragraph delimiters. Paragraphs provide a coherent and self-contained unit of information suitable for RAG.</li> | ||
<li>Semantic Chunking: Semantic chunking involves analyzing the text and identifying meaningful semantic units or phrases. This can be achieved using techniques like named entity recognition, noun phrase extraction, or dependency parsing. Semantic chunks capture the core concepts and ideas within the text.</li> | ||
<li>Custom Chunking: Elixir provides the flexibility to define custom chunking rules based on specific requirements. For example, you can chunk text based on a certain number of words, specific delimiters, or regular expressions that match particular patterns.</li> | ||
</ol> | ||
<p>The choice of chunking approach depends on the nature of the text and the desired granularity of retrieval and generation. Elixir's powerful string manipulation and pattern matching capabilities make it easy to implement various chunking strategies efficiently.</p> | ||
</article> | ||
|
||
<section> | ||
<h3>Benefits of Elixir/Erlang</h3> | ||
<h4>Elixir and Erlang offer several advantages over other language stacks when it comes to building scalable and fault-tolerant systems. Let's take a look at some of the key benefits:</h4> | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>Benefit</th> | ||
<th>Description</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<td>Concurrency and Scalability</td> | ||
<td>Built-in support for lightweight processes and efficient message passing.</td> | ||
</tr> | ||
<tr> | ||
<td>Fault-Tolerance</td> | ||
<td>"Let it crash" philosophy and automatic recovery from failures.</td> | ||
</tr> | ||
<tr> | ||
<td>Hot Code Swapping</td> | ||
<td>Update code without stopping the system, providing zero downtime.</td> | ||
</tr> | ||
<tr> | ||
<td>Distribution and Clustering</td> | ||
<td>Built-in support for distributed systems and easy horizontal scaling.</td> | ||
</tr> | ||
<tr> | ||
<td>Ecosystem and Libraries</td> | ||
<td>Growing ecosystem with a wide range of libraries and supportive community.</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
<p>These benefits make Elixir and Erlang a compelling choice for building scalable, fault-tolerant, and maintainable systems, especially in domains like web development, real-time applications, and distributed systems.</p> | ||
</section> | ||
|
||
<h5>Conclusion</h5> | ||
<p>Elixir's combination of functional programming, concurrency, and fault-tolerance makes it a powerful language for building scalable and maintainable RAG systems. By leveraging the appropriate chunking approaches and utilizing Elixir's strengths, you can create efficient and high-quality retrieval augmented generation solutions.</p> | ||
|
||
<h6>© Elixir RAG. All rights reserved.</h6> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for organising these!