Notebooks
G
Google Gemini
Code Analysis Using Gemini LangChain And DeepLake

Code Analysis Using Gemini LangChain And DeepLake

gemini-cookbookgemini-apiexamplesgeminilangchain
Copyright 2025 Google LLC.
[ ]

Gemini API: Code analysis using LangChain and DeepLake

⚠️

This notebook requires paid tier rate limits to run properly.
(cf. pricing for more details).

This notebook shows how to use Gemini API with Langchain and DeepLake for code analysis. The notebook will teach you:

  • loading and splitting files
  • creating a Deeplake database with embedding information
  • setting up a retrieval QA chain

Load dependencies

[ ]
[1]

Configure your API key

To run the following cell, your API key must be stored in a Colab Secret named GEMINI_API_KEY. If you don't already have an API key, or you're not sure how to create a Colab Secret, see Authentication for an example.

[ ]

Prepare the files

First, download a langchain-google repository. It is the repository you will analyze in this example.

It contains code integrating Gemini API, VertexAI, and other Google products with langchain.

[ ]

This example will focus only on the integration of Gemini API with langchain and ignore the rest of the codebase.

[3]

Each file with a matching path will be loaded and split by RecursiveCharacterTextSplitter. In this example, it is specified, that the files are written in Python. It helps split the files without having documents that lack context.

[4]

Language Enum provides common separators used in most popular programming languages, it lowers the chances of classes or functions being split in the middle.

[5]
['\nclass ', '\ndef ', '\n\tdef ', '\n\n', '\n', ' ', '']

Create the database

The data will be loaded into the memory since the database doesn't need to be permanent in this case and is small enough to fit.

The type of storage used is specified by prefix in the path, in this case by mem://.

Check out other types of storage here.

[6]
[22]

Everything needed is ready, and now you can create the database. It should not take longer than a few seconds.

[27]

Question Answering

Set-up the document retriever.

[28]
[29]

Now, you can create a chain for Question Answering. In this case, RetrievalQA chain will be used.

If you want to use the chat option instead, use ConversationalRetrievalChain.

[30]

The chain is ready to answer your questions.

NOTE: Markdown is used for improved formatting of the output.

[31]
[32]
[33]
[34]
[35]

Summary

Gemini API works great with Langchain. The integration is seamless and provides an easy interface for:

  • loading and splitting files
  • creating DeepLake database with embeddings
  • answering questions based on context from files

What's next?

This notebook showed only one possible use case for langchain with Gemini API. You can find many more here.