Create a template code based on existing code base

I have a use case where I need to create an initial draft python code based on existing corpus of code. I am thinking whether retrieval augmented generation will work in this case. Not sure if text embeddings will do a good job in similarity against code embeddings. One option is to explain the existing code in text and embed that and then use RAG. It will be great to know if anyone has tried any other techniques.

I fed it some of the langchain prompt templating docs, and had it act as a code interpreter to create prompt objects that create modifications of a given langchain abstraction (passed in tools, agents, retrievers, and prompts). In theory you could use that to generate permutations of any given abstraction in your code, although the variation seems to increase the more steps are involved. In practice this meant it wasn’t a good idea if the consistency needed to be rigid.