function get_all_dbo_concepthouses
Queries a Neo4j graph database to retrieve nodes of type dbo_ConceptHouses with a configurable limit on the number of results returned.
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
646 - 653
simple
Purpose
This function is designed to fetch concept house nodes from a Neo4j database, specifically targeting nodes labeled as 'dbo_ConceptHouses'. It's useful for retrieving architectural or conceptual housing data from a knowledge graph, with built-in result limiting to prevent overwhelming queries. The function relies on an external 'run_query' helper function to execute the Cypher query.
Source Code
def get_all_dbo_concepthouses(limit=100):
"""Return dbo_ConceptHouses nodes (limited to 25)"""
query = """
MATCH (n:dbo_ConceptHouses)
RETURN n
LIMIT $limit
"""
return run_query(query, {"limit": limit})
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
limit |
- | 100 | positional_or_keyword |
Parameter Details
limit: Integer value that controls the maximum number of dbo_ConceptHouses nodes to return from the database. Default is 100, though the docstring incorrectly states 25. Must be a positive integer. Higher values may impact performance depending on database size.
Return Value
Returns the result of the run_query function execution, which typically contains a list or collection of Neo4j node objects matching the dbo_ConceptHouses label. The exact return type depends on the implementation of run_query, but commonly returns a list of dictionaries or Neo4j Record objects containing node properties. Returns up to 'limit' number of nodes.
Dependencies
neo4j
Required Imports
from neo4j import GraphDatabase
Usage Example
# Assuming run_query is defined and Neo4j connection is configured
# Example run_query implementation:
def run_query(query, params):
driver = GraphDatabase.driver('bolt://localhost:7687', auth=('neo4j', 'password'))
with driver.session() as session:
result = session.run(query, params)
return [record['n'] for record in result]
driver.close()
# Get default 100 concept houses
results = get_all_dbo_concepthouses()
print(f'Retrieved {len(results)} concept houses')
# Get only 10 concept houses
limited_results = get_all_dbo_concepthouses(limit=10)
for house in limited_results:
print(house)
Best Practices
- The docstring incorrectly states the limit is 25 when the default parameter is 100 - this should be corrected for consistency
- Ensure the run_query function properly handles database connections and closes them to prevent connection leaks
- Consider adding error handling for cases where the database is unavailable or the query fails
- Be mindful of the limit parameter when working with large datasets to avoid performance issues
- Consider adding type hints for better code documentation (e.g., limit: int -> List[Dict])
- The function assumes run_query is available in scope - ensure proper import or definition
- For production use, implement proper connection pooling and session management in run_query
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function get_dbo_concepthouses_with_references_houses_dbo_houses 88.1% similar
-
function get_all_dbo_houses 87.9% similar
-
function get_dbo_concepthouses_with_references_concepts_dbo_concepts 87.3% similar
-
function get_dbo_concepthouses_by_id 84.9% similar
-
function get_all_dbo_concepts 82.6% similar