DeepSearch Graph Language Models
deepsearch-glm is a Python library that enables the creation and querying of Graph Language Models (GLMs). It integrates Large Language Models (LLMs) with knowledge graphs derived from unstructured documents, primarily leveraging the `deepsearch-toolkit` library for graph processing. The current version is 1.0.0, and it's actively developed by DeepSearch AI, with releases expected to follow a feature-driven cadence.
Common errors
-
ModuleNotFoundError: No module named 'torch'
cause The underlying `transformers` library, used by `deepsearch-glm`, requires a machine learning backend (PyTorch or TensorFlow) which was not installed.fixInstall the necessary backend: `pip install torch` (recommended) or `pip install tensorflow`. Alternatively, install `deepsearch-glm` with all extras: `pip install deepsearch-glm[all]`. -
ImportError: cannot import name 'Document' from 'deepsearch.glm.core.models'
cause The `Document` model, crucial for representing input documents, originates from the `deepsearch-toolkit` library, not directly from `deepsearch-glm`'s core models.fixUse the correct import path: `from deepsearch.documents.core.models import Document`. -
OSError: Can't load 'deepsearch-ai/deepsearch-glm-base' model. Make sure that...
cause This error typically indicates issues during the model download or loading process, such as network problems, insufficient disk space, corrupted cache, or an incorrect model ID.fixCheck your internet connection, ensure sufficient disk space, and verify the model name (`deepsearch-ai/deepsearch-glm-base`). If issues persist, try clearing the Hugging Face cache (e.g., `rm -rf ~/.cache/huggingface/hub`) and retrying.
Warnings
- gotcha The `GraphLanguageModel.from_pretrained()` method will download a large language model (e.g., `deepsearch-glm-base` is ~1.5GB) on its first invocation. This requires significant disk space, memory, and an active internet connection, and may take considerable time.
- gotcha While `deepsearch-glm` simplifies interaction with GLMs, its core functionality for processing documents into knowledge graphs heavily relies on `deepsearch-toolkit`. For advanced graph manipulation or custom document processing, direct usage and understanding of `deepsearch-toolkit` is often necessary.
- gotcha The underlying Large Language Models (via `transformers`) require a machine learning backend like PyTorch (`torch`) or TensorFlow (`tensorflow`). While `deepsearch-glm` lists these as optional dependencies, practically, one of them is required for the library to function. You might encounter `ModuleNotFoundError` if neither is installed.
Install
-
pip install deepsearch-glm -
pip install deepsearch-glm[all]
Imports
- GraphLanguageModel
from deepsearch.glm.core.glm import GraphLanguageModel
- GlmQuery
from deepsearch.glm.queries import GlmQuery
- Document
from deepsearch.glm.core.models import Document
from deepsearch.documents.core.models import Document
Quickstart
import os
from deepsearch.glm.core.glm import GraphLanguageModel
from deepsearch.glm.queries import GlmQuery
from deepsearch.documents.core.models import Document
# Note: The deepsearch-glm-base model is large (~1.5GB) and will be downloaded on first run.
# This example requires deepsearch-toolkit to implicitly process documents into a graph.
try:
# 1. Initialize the GraphLanguageModel (this will download a model if not cached)
# This might take a while and uses significant memory/disk space.
print("Loading GraphLanguageModel... (first run may download ~1.5GB model)")
glm_model = GraphLanguageModel.from_pretrained("deepsearch-ai/deepsearch-glm-base")
print("GraphLanguageModel loaded.")
# 2. Prepare a dummy document. In a real scenario, this would be processed
# by deepsearch-toolkit to extract a knowledge graph before querying.
doc_content = "The DeepSearch AI platform helps enterprises extract insights from unstructured data using advanced AI."
dummy_document = Document(name="deepsearch_info.txt", content=doc_content)
# 3. Create a query
question = "What is the DeepSearch AI platform used for?"
query = GlmQuery(
model=glm_model,
documents=[dummy_document], # Provide documents directly for implicit graph creation
query_text=question
)
# 4. Run the query
print(f"\nQuerying: {question}")
result = query.run()
# 5. Print the result
print("\nQuery Result:")
print(result.answer)
except ImportError as e:
print(f"Error: {e}. Ensure all core and optional dependencies (like 'transformers', 'torch' or 'tensorflow') are installed.")
print("Try: pip install deepsearch-glm[all]")
except Exception as e:
print(f"An error occurred during execution: {e}")
print("Common issues include insufficient disk space, network problems during model download, or missing ML backend (torch/tensorflow).")