GraphRAG-style Python SDK for GibRAM - Graph in-Buffer Retrieval & Associative Memory
Project description
GibRAM Python SDK v0.2.0
GraphRAG-style knowledge graph indexing with automatic entity extraction, relationship detection, and community discovery.
Installation
pip install gibram
Quick Start
from gibram import GibRAMIndexer
# Initialize indexer with OpenAI
indexer = GibRAMIndexer(
session_id="my-project",
llm_api_key="sk-...", # or set OPENAI_API_KEY env
)
# Index documents (automatic chunking, extraction, embedding)
stats = indexer.index_documents([
"Einstein was born in 1879 in Ulm, Germany.",
"He developed the theory of relativity in 1905.",
"Einstein received the Nobel Prize in Physics in 1921.",
])
print(f"Indexed {stats.entities_extracted} entities in {stats.indexing_time_seconds:.2f}s")
# Query knowledge graph
result = indexer.query("Einstein's achievements", top_k=5)
for entity in result.entities:
print(f"{entity.title} ({entity.type}): {entity.description}")
Configuration
Environment Variables
export OPENAI_API_KEY="sk-..."
Initialization Parameters
indexer = GibRAMIndexer(
# Required
session_id="unique-project-id",
# Server connection
host="localhost",
port=6161,
# LLM configuration
llm_provider="openai", # Only OpenAI supported currently
llm_api_key="sk-...", # Auto-detect from OPENAI_API_KEY
llm_model="gpt-4o", # GPT-4o recommended
# Embedding configuration
embedding_provider="openai",
embedding_model="text-embedding-3-small",
embedding_dimensions=1536, # Must match server config
# Chunking configuration
chunk_size=512, # Tokens per chunk
chunk_overlap=50, # Overlap between chunks
# Community detection
auto_detect_communities=True, # Auto-run after indexing
community_resolution=1.0, # Leiden algorithm resolution
)
API Reference
GibRAMIndexer
Main class for indexing and querying.
index_documents(documents, batch_size=10, show_progress=True) -> IndexStats
Index documents into knowledge graph.
Arguments:
documents: List of strings or dicts{"id": ..., "text": ..., "metadata": ...}batch_size: Batch size for LLM/API calls (default: 10)show_progress: Show progress bar (default: True)
Returns: IndexStats with counts and timing
Pipeline:
- Chunk documents → TextUnits
- Extract entities & relationships (LLM)
- Generate embeddings
- Store in graph
- Link entities to text units
- Detect communities (if enabled)
Example:
stats = indexer.index_documents([
{"id": "doc1", "text": "...", "metadata": {"source": "wiki"}},
{"id": "doc2", "text": "..."},
])
query(query, mode="local", top_k=10, include_entities=True, include_text_units=True, include_communities=False) -> QueryResult
Query knowledge graph.
Arguments:
query: Natural language querymode: Query mode (currently only supports "local")top_k: Number of results (default: 10)include_entities: Include entity resultsinclude_text_units: Include text unit resultsinclude_communities: Include community results
Returns: QueryResult with scored results
Example:
result = indexer.query("machine learning applications", top_k=5)
for entity in result.entities:
print(f"{entity.title}: {entity.score:.3f}")
for text_unit in result.text_units:
print(f"{text_unit.content[:100]}... (score: {text_unit.score:.3f})")
get_stats() -> IndexStats
Get current indexing statistics.
close()
Close connection to server.
Types
IndexStats
@dataclass
class IndexStats:
documents_indexed: int = 0
text_units_created: int = 0
entities_extracted: int = 0
relationships_extracted: int = 0
communities_detected: int = 0
indexing_time_seconds: float = 0.0
QueryResult
@dataclass
class QueryResult:
entities: List[ScoredEntity]
text_units: List[ScoredTextUnit]
communities: List[ScoredCommunity]
execution_time_ms: float
ScoredEntity
@dataclass
class ScoredEntity:
id: int
title: str
type: str
description: str
score: float # Similarity score
Exceptions
All exceptions inherit from GibRAMError:
ConnectionError: Server connection failedTimeoutError: Operation timed outProtocolError: Protocol encoding/decoding errorServerError: Server returned errorNotFoundError: Resource not foundValidationError: Input validation failedExtractionError: LLM extraction failedEmbeddingError: Embedding generation failedConfigurationError: Invalid configuration
Advanced Usage
Custom Extractors
Implement BaseExtractor for custom entity/relationship extraction:
from gibram.extractors import BaseExtractor
from gibram.types import ExtractedEntity, ExtractedRelationship
class MyExtractor(BaseExtractor):
def extract(self, text: str) -> tuple[list[ExtractedEntity], list[ExtractedRelationship]]:
# Your custom logic
entities = [...]
relationships = [...]
return entities, relationships
indexer = GibRAMIndexer(
session_id="custom",
extractor=MyExtractor(),
embedder=..., # Still need embedder
)
Custom Embedders
Implement BaseEmbedder for custom embeddings:
from gibram.embedders import BaseEmbedder
class MyEmbedder(BaseEmbedder):
def embed(self, texts: list[str]) -> list[list[float]]:
# Your custom logic
return [[0.1, 0.2, ...], ...]
def embed_single(self, text: str) -> list[float]:
return self.embed([text])[0]
indexer = GibRAMIndexer(
session_id="custom",
embedder=MyEmbedder(),
)
Context Manager
Use context manager for automatic cleanup:
with GibRAMIndexer(session_id="project") as indexer:
stats = indexer.index_documents(documents)
result = indexer.query("some query")
# Connection automatically closed
Requirements
- Python 3.8+
- GibRAM server running (Docker recommended)
- OpenAI API key (for extraction & embeddings)
Server Setup
Start GibRAM server with Docker:
docker run -d \
--name gibram-server \
-p 6161:6161 \
-e EMBEDDING_DIM=1536 \
gibram:latest
License
MIT
Version
v0.2.0 - Current release v0.1.0 - Initial release with OpenAI extraction & embeddings
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gibram-0.2.0.tar.gz.
File metadata
- Download URL: gibram-0.2.0.tar.gz
- Upload date:
- Size: 25.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
59b4105e0eeeb2c3a31103bb16333bd2cc448fbc9b49ed47f88ae98ac8329c30
|
|
| MD5 |
29bb39df46b088dc80c91c079f32cd37
|
|
| BLAKE2b-256 |
c2991e80c9e6dc30a1737aefc9150220f07c41367fc99b52787f92f250869be5
|
Provenance
The following attestation bundles were made for gibram-0.2.0.tar.gz:
Publisher:
publish.yml on gibram-io/gibram
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gibram-0.2.0.tar.gz -
Subject digest:
59b4105e0eeeb2c3a31103bb16333bd2cc448fbc9b49ed47f88ae98ac8329c30 - Sigstore transparency entry: 879781660
- Sigstore integration time:
-
Permalink:
gibram-io/gibram@96d3b584fa7d8bd5b795e3fd7e5feb429ef273cc -
Branch / Tag:
refs/tags/sdk-python/v0.2.0 - Owner: https://github.com/gibram-io
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@96d3b584fa7d8bd5b795e3fd7e5feb429ef273cc -
Trigger Event:
push
-
Statement type:
File details
Details for the file gibram-0.2.0-py3-none-any.whl.
File metadata
- Download URL: gibram-0.2.0-py3-none-any.whl
- Upload date:
- Size: 28.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3e9bdfa094e4fd0999439d0dc1e2e1879275a9991c144e3b3618710074d5bf67
|
|
| MD5 |
82ef3e950834192586190159f2a3e085
|
|
| BLAKE2b-256 |
56481272e4ae65e3903108e63a5b7846a1036c8403d4e6e1a0d25a5b8e0e5bdd
|
Provenance
The following attestation bundles were made for gibram-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on gibram-io/gibram
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gibram-0.2.0-py3-none-any.whl -
Subject digest:
3e9bdfa094e4fd0999439d0dc1e2e1879275a9991c144e3b3618710074d5bf67 - Sigstore transparency entry: 879781723
- Sigstore integration time:
-
Permalink:
gibram-io/gibram@96d3b584fa7d8bd5b795e3fd7e5feb429ef273cc -
Branch / Tag:
refs/tags/sdk-python/v0.2.0 - Owner: https://github.com/gibram-io
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@96d3b584fa7d8bd5b795e3fd7e5feb429ef273cc -
Trigger Event:
push
-
Statement type: