The Glean Indexing API allows customers to put arbitrary content in the search index, making it available for Generative AI applications. This is particularly useful for performing permissions-aware searches over content in internal tools that reside on-premises, as well as for searching over applications that Glean does not currently support first class. Additionally, these APIs allow the customer to push organization data (people info, organization structure, etc.) into Glean.
In addition to documents, the Indexing API also supports indexing custom entities. These are structured key-value content, as opposed to being text heavy like documents. This feature is useful when the information is in the form of structured schema that can be represented as key-value type attributes.
Glean provides advance notice of any planned backwards incompatible changes along with a sunset period for anything that requires developers to adopt the new versions.
Official API Clients
Glean provides official API clients for the Indexing API in multiple languages:
Installing the Indexing API Clients
Install the Python client
pip install glean-api-client
Or using Poetry:
poetry add glean-api-client
Initialize the client
from glean import Glean
import os
# Initialize with API token
with Glean(
api_token=os.getenv("GLEAN_INDEXING_API_TOKEN", ""),
) as client:
# Use the client for indexing operations
pass
Example usage
from glean import Glean, models
import os
with Glean(
api_token=os.getenv("GLEAN_INDEXING_API_TOKEN", ""),
) as client:
# Index a document
response = client.indexing.documents.index(request={
"datasource": "my-datasource",
"documents": [
{
"id": "doc-123",
"title": "Sample Document",
"content": "This is a sample document to index in Glean.",
"url": "https://example.com/documents/123",
"permissions": {
"users": ["user@example.com"],
"groups": ["everyone@example.com"]
}
}
]
})
print(response)
Install the Python client
pip install glean-api-client
Or using Poetry:
poetry add glean-api-client
Initialize the client
from glean import Glean
import os
# Initialize with API token
with Glean(
api_token=os.getenv("GLEAN_INDEXING_API_TOKEN", ""),
) as client:
# Use the client for indexing operations
pass
Example usage
from glean import Glean, models
import os
with Glean(
api_token=os.getenv("GLEAN_INDEXING_API_TOKEN", ""),
) as client:
# Index a document
response = client.indexing.documents.index(request={
"datasource": "my-datasource",
"documents": [
{
"id": "doc-123",
"title": "Sample Document",
"content": "This is a sample document to index in Glean.",
"url": "https://example.com/documents/123",
"permissions": {
"users": ["user@example.com"],
"groups": ["everyone@example.com"]
}
}
]
})
print(response)
Install the TypeScript client
npm install @gleanwork/api-client
Or using Yarn:
yarn add @gleanwork/api-client
Initialize the client
import { Glean } from "@gleanwork/api-client";
// Initialize with API token
const client = new Glean({
apiToken: process.env.GLEAN_INDEXING_API_TOKEN,
instance: process.env.GLEAN_INSTANCE,
});
Example usage
import { Glean } from "@gleanwork/api-client";
async function run() {
const glean = new Glean({
apiToken: process.env.GLEAN_INDEXING_API_TOKEN,
instance: process.env.GLEAN_INSTANCE,
});
// Index a document
const response = await glean.indexing.documents.index({
datasource: "my-datasource",
documents: [
{
datasource: "my-datasource",
id: "doc-123",
title: "Sample Document",
viewURL: "https://example.com/documents/123",
body: {
mimeType: "text/plain",
textContent: "This is a sample document to index in Glean.",
},
permissions: {
allowedUsers: [{ email: "user@example.com" }],
allowedGroups: ["everyone@example.com"]
}
}
]
});
console.log(response);
}
run();
Install the Go client
go get github.com/gleanwork/api-client-go
Initialize the client
import (
"context"
glean "github.com/gleanwork/api-client-go"
"os"
)
func main() {
ctx := context.Background()
// Initialize with API token
client := glean.New(
glean.WithAPIToken(os.Getenv("GLEAN_INDEXING_API_TOKEN")),
)
}
Example usage
import (
"context"
"fmt"
glean "github.com/gleanwork/api-client-go"
"os"
)
func main() {
ctx := context.Background()
client := glean.New(
glean.WithAPIToken(os.Getenv("GLEAN_INDEXING_API_TOKEN")),
)
// Index a document
response, err := client.Indexing.Documents.Index(ctx, &glean.IndexDocumentsRequest{
Datasource: "my-datasource",
Documents: []glean.Document{
{
ID: "doc-123",
Title: "Sample Document",
Content: "This is a sample document to index in Glean.",
URL: "https://example.com/documents/123",
Permissions: &glean.DocumentPermissions{
Users: []string{"user@example.com"},
Groups: []string{"everyone@example.com"},
},
},
},
})
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
fmt.Println(response)
}
Add dependency to your project
Maven:
<dependency>
<groupId>com.glean.api-client</groupId>
<artifactId>glean-api-client</artifactId>
<version>0.x.x</version> <!-- Use latest version -->
</dependency>
Gradle:
implementation 'com.glean.api-client:glean-api-client:0.x.x' // Use latest version
Initialize the client
import com.glean.api_client.glean_api_client.Glean;
public class Application {
public static void main(String[] args) {
// Initialize with API token
Glean apiClient = Glean.builder()
.apiToken(System.getenv("GLEAN_INDEXING_API_TOKEN"))
.build();
}
}
Example usage
import com.glean.api_client.glean_api_client.Glean;
import com.glean.api_client.glean_api_client.models.components.*;
import com.glean.api_client.glean_api_client.models.operations.IndexDocumentsResponse;
import java.util.Arrays;
import java.util.List;
public class Application {
public static void main(String[] args) {
Glean apiClient = Glean.builder()
.apiToken(System.getenv("GLEAN_INDEXING_API_TOKEN"))
.build();
// Create document with permissions
DocumentPermissions permissions = DocumentPermissions.builder()
.users(Arrays.asList("user@example.com"))
.groups(Arrays.asList("everyone@example.com"))
.build();
Document document = Document.builder()
.id("doc-123")
.title("Sample Document")
.content("This is a sample document to index in Glean.")
.url("https://example.com/documents/123")
.permissions(permissions)
.build();
// Index the document
IndexDocumentsResponse response = apiClient.indexing().documents().index()
.request(IndexDocumentsRequest.builder()
.datasource("my-datasource")
.documents(Arrays.asList(document))
.build())
.call();
// Handle response
System.out.println(response);
}
}
For more detailed information, please refer to the API Reference.