Skip to content
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

Add ability to parse code #293

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

santib
Copy link
Contributor

@santib santib commented Aug 12, 2023

Something like this is needed so we can load codebases in Vector DBs

@andreibondarev
Copy link
Collaborator

@santib This opens up an interesting problem -- how do we chunk code?

@santib
Copy link
Contributor Author

santib commented Aug 14, 2023

@santib This opens up an interesting problem -- how do we chunk code?

Yeah, I just used the Text one for simplicity, but checking https://python.langchain.com/docs/modules/data_connection/document_transformers/text_splitters/code_splitter seems like they get the separators for each language, and that's it.

I can change this PR to do something similar if you want

@andreibondarev
Copy link
Collaborator

@santib Yeah, I like that!

def chunks(options = {})
if Langchain::Processors::Code::EXTENSIONS.include?(source_type)
options = options.merge(separators: Langchain::Chunker::Base::LANG_SEPARATORS[source_type])
Langchain::Chunker::RecursiveText.new(@data, **options).chunks
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: add tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants