ExLLM.Providers.Gemini.Corpus (ex_llm v0.8.1)
View SourceGoogle Gemini Corpus Management API implementation.
Corpora are collections of Documents used for semantic retrieval. A project can create up to 5 corpora.
Usage
# Create a corpus
{:ok, corpus} = ExLLM.Providers.Gemini.Corpus.create_corpus(%{
display_name: "My Knowledge Base"
}, oauth_token: "your-oauth-token")
# List corpora
{:ok, response} = ExLLM.Providers.Gemini.Corpus.list_corpora(%{
page_size: 10
}, oauth_token: "your-oauth-token")
# Query a corpus
{:ok, response} = ExLLM.Providers.Gemini.Corpus.query_corpus(
"corpora/my-corpus",
"search query",
%{results_count: 5},
oauth_token: "your-oauth-token"
)
# Update corpus
{:ok, corpus} = ExLLM.Providers.Gemini.Corpus.update_corpus(
"corpora/my-corpus",
%{display_name: "Updated Name"},
["displayName"],
oauth_token: "your-oauth-token"
)
# Delete corpus
:ok = ExLLM.Providers.Gemini.Corpus.delete_corpus(
"corpora/my-corpus",
oauth_token: "your-oauth-token"
)
Summary
Functions
Builds a CreateCorpusRequest struct from the given parameters.
Builds a ListCorporaRequest struct from the given parameters.
Builds a QueryCorpusRequest struct from the given parameters.
Builds an UpdateCorpusRequest struct from the given parameters.
Creates a new corpus.
Deletes a corpus.
Formats an operator string from the API to an atom.
Gets information about a specific corpus.
Lists corpora owned by the user.
Converts an operator atom to the API string format.
Parses a corpus response from the API.
Parses a list corpora response from the API.
Parses a query corpus response from the API.
Performs semantic search over a corpus.
Updates a corpus.
Validates if a corpus name has the correct format.
Validates if a display name has a valid length.
Functions
@spec build_create_corpus_request(map()) :: ExLLM.Providers.Gemini.Corpus.CreateCorpusRequest.t()
Builds a CreateCorpusRequest struct from the given parameters.
@spec build_list_corpora_request(keyword() | map()) :: ExLLM.Providers.Gemini.Corpus.ListCorporaRequest.t()
Builds a ListCorporaRequest struct from the given parameters.
@spec build_query_corpus_request(String.t(), String.t(), map()) :: ExLLM.Providers.Gemini.Corpus.QueryCorpusRequest.t()
Builds a QueryCorpusRequest struct from the given parameters.
@spec build_update_corpus_request(String.t(), map(), [String.t()]) :: ExLLM.Providers.Gemini.Corpus.UpdateCorpusRequest.t()
Builds an UpdateCorpusRequest struct from the given parameters.
@spec create_corpus(map(), Keyword.t()) :: {:ok, ExLLM.Providers.Gemini.Corpus.CorpusInfo.t()} | {:error, map()}
Creates a new corpus.
Parameters
corpus_data
- Map containing corpus information:name
- Optional corpus name (will be auto-generated if not provided):display_name
- Optional human-readable display name
opts
- Options including OAuth2 token
Options
:oauth_token
- OAuth2 token (required for corpus operations)
Examples
# Create corpus with auto-generated name
{:ok, corpus} = ExLLM.Providers.Gemini.Corpus.create_corpus(%{
display_name: "My Knowledge Base"
}, oauth_token: "your-oauth-token")
# Create corpus with specific name
{:ok, corpus} = ExLLM.Providers.Gemini.Corpus.create_corpus(%{
name: "corpora/my-custom-corpus",
display_name: "Custom Corpus"
}, oauth_token: "your-oauth-token")
Deletes a corpus.
Parameters
corpus_name
- The name of the corpus to deleteopts
- Options including OAuth2 token and force flag:force
- If true, delete all documents in the corpus as well
Examples
# Delete empty corpus
:ok = ExLLM.Providers.Gemini.Corpus.delete_corpus(
"corpora/my-corpus",
oauth_token: "your-oauth-token"
)
# Force delete corpus with documents
:ok = ExLLM.Providers.Gemini.Corpus.delete_corpus(
"corpora/my-corpus",
oauth_token: "your-oauth-token",
force: true
)
Formats an operator string from the API to an atom.
@spec get_corpus(String.t(), Keyword.t()) :: {:ok, ExLLM.Providers.Gemini.Corpus.CorpusInfo.t()} | {:error, map()}
Gets information about a specific corpus.
Parameters
corpus_name
- The name of the corpus (e.g., "corpora/my-corpus")opts
- Options including OAuth2 token
Examples
{:ok, corpus} = ExLLM.Providers.Gemini.Corpus.get_corpus(
"corpora/my-corpus",
oauth_token: "your-oauth-token"
)
@spec list_corpora(keyword() | map(), Keyword.t()) :: {:ok, ExLLM.Providers.Gemini.Corpus.ListCorporaResponse.t()} | {:error, map()}
Lists corpora owned by the user.
Parameters
list_options
- Map containing pagination options:page_size
- Optional maximum number of corpora per page (1-20):page_token
- Optional page token for pagination
opts
- Options including OAuth2 token
Examples
# List all corpora
{:ok, response} = ExLLM.Providers.Gemini.Corpus.list_corpora(%{},
oauth_token: "your-oauth-token")
# List with pagination
{:ok, response} = ExLLM.Providers.Gemini.Corpus.list_corpora(%{
page_size: 5,
page_token: "next_page_token"
}, oauth_token: "your-oauth-token")
Converts an operator atom to the API string format.
@spec parse_corpus_response(map()) :: ExLLM.Providers.Gemini.Corpus.CorpusInfo.t()
Parses a corpus response from the API.
@spec parse_list_corpora_response(map()) :: ExLLM.Providers.Gemini.Corpus.ListCorporaResponse.t()
Parses a list corpora response from the API.
@spec parse_query_corpus_response(map()) :: ExLLM.Providers.Gemini.Corpus.QueryCorpusResponse.t()
Parses a query corpus response from the API.
@spec query_corpus(String.t(), String.t(), map(), Keyword.t()) :: {:ok, ExLLM.Providers.Gemini.Corpus.QueryCorpusResponse.t()} | {:error, map()}
Performs semantic search over a corpus.
Parameters
corpus_name
- The name of the corpus to queryquery
- The search query stringquery_options
- Map containing query options:results_count
- Maximum number of chunks to return (1-100):metadata_filters
- List of metadata filters
opts
- Options including OAuth2 token
Examples
# Simple query
{:ok, response} = ExLLM.Providers.Gemini.Corpus.query_corpus(
"corpora/my-corpus",
"artificial intelligence",
%{results_count: 10},
oauth_token: "your-oauth-token"
)
# Query with metadata filters
{:ok, response} = ExLLM.Providers.Gemini.Corpus.query_corpus(
"corpora/my-corpus",
"machine learning",
%{
results_count: 5,
metadata_filters: [
%{
key: "document.custom_metadata.category",
conditions: [
%{string_value: "technology", operation: "EQUAL"}
]
}
]
},
oauth_token: "your-oauth-token"
)
@spec update_corpus(String.t(), map(), [String.t()], Keyword.t()) :: {:ok, ExLLM.Providers.Gemini.Corpus.CorpusInfo.t()} | {:error, map()}
Updates a corpus.
Parameters
corpus_name
- The name of the corpus to updateupdate_data
- Map containing fields to update:display_name
- New display name
update_mask
- List of fields to update (currently only ["displayName"] is supported)opts
- Options including OAuth2 token
Examples
{:ok, corpus} = ExLLM.Providers.Gemini.Corpus.update_corpus(
"corpora/my-corpus",
%{display_name: "Updated Name"},
["displayName"],
oauth_token: "your-oauth-token"
)
Validates if a corpus name has the correct format.
Validates if a display name has a valid length.