Grepedia
GL

Glean

Glean is an open-source system that stores, indexes, and queries typed, schema-defined facts about source code to provide deep, semantic insights into codebases.

Score0
About

Glean is an open-source system designed for collecting, storing, and querying typed, schema-defined facts about source code. Developed by Meta, it serves as a powerful engine for code analysis, allowing developers to move beyond simple text-based searching like grep to perform deep, semantic reasoning over entire codebases. By storing information in a queryable database, it empowers IDEs, coding agents, and custom developer tooling to provide accurate, context-aware answers regarding symbol definitions, cross-file references, call hierarchies, and complex type resolution. Glean is built to handle massive monorepos, offering high-efficiency storage and retrieval that scales to billions of facts.

The core functionality of Glean relies on a schema-based data model where code constructs—such as definitions, imports, and inheritance—are treated as facts within a directed acyclic graph. These facts are generated by language-specific indexers and stored in an efficient backend, currently built on RocksDB, which handles deduplication and compact representation. Users interact with this data using Angle, a high-level declarative query language inspired by Datalog. Angle is designed to be expressive and precise, enabling complex, cross-language navigation that traditional compilers or static analysis tools might struggle to perform at scale. The system also supports derived predicates, which allow for the on-demand or pre-calculated computation of new facts based on existing ones, further extending the utility and flexibility of the stored data.

Some of the key features are:

  • Semantic code graph: Captures relationships like call graphs, type hierarchies, and references rather than just text matches.
  • Multi-language: Provides robust support for numerous languages including C++, Hack, Python, Haskell, Flow, .NET, Go, Java, Rust, and TypeScript.
  • Built for scale: Engineered to index and query monorepos containing billions of facts with incremental updates.
  • Angle query language: A typed, declarative language for composing complex, precise questions across the codebase.
  • Agent- and tool-friendly: Integrates via CLI, language-specific APIs, or Thrift, facilitating use in IDEs, refactoring bots, and LLM agents.
  • Extensible schemas: Enables users to define custom predicates to capture domain-specific facts, such as test coverage or profiling data.
  • Language Server Protocol support: Includes a generic LSP server to provide standard IDE features like go-to-definition and symbol search across large projects.

Operationally, Glean acts as a central repository for code intelligence. Developers run indexers against their source code to populate a database, which can then be served via the Glean server. Clients connect to this server to execute Angle queries, either through an interactive shell for exploration or programmatically through APIs for integration into production workflows. It supports incremental indexing, allowing for fast updates to the database when code changes occur, ensuring the system remains current without requiring full re-indexing of the entire repository. This architecture allows multiple versions of a database to exist simultaneously, with stacked incremental updates that keep the overall data footprint manageable.

Some common use cases include:

  • Code navigation: Implementing high-speed, accurate jump-to-definition and reference searching for IDE plugins.
  • Refactoring & migrations: Identifying all call sites, implementers, or overrides across a massive monorepo during large-scale API updates.
  • Code search agents & LLMs: Grounding AI coding assistant answers in real, verified symbol relationships instead of heuristic-based search.
  • Dependency analysis: Mapping transitive module or file-level dependencies to perform impact analysis on proposed changes.
  • Code review automation: Using factual code analysis to reason about the potential effects of a code change automatically.