When implementing knowledge-graph storage/search, proactively prevent expensive work and payload bloat by following these rules:
1) Minimize returned payloads (especially vectors)
_embedding instead of embedding) so queries that don’t need vectors don’t fetch them.2) Make one-time setup idempotent
3) Batch compute for similarity search
4) Bound expensive retrieval early
topk/chunk limits during the query/explore step. Avoid relying on later “context trimming” hacks; constrain the result set at the source.5) Avoid repeated iteration during persistence
Example (index-create guard pattern):
class Adapter:
def __init__(self):
self._chunk_vector_index_created = False
self._entity_vector_index_created = False
def upsert_chunks(self, chunks):
# ... upsert data ...
if not self._chunk_vector_index_created:
self._create_chunk_vector_index()
self._chunk_vector_index_created = True
def upsert_entities(self, entities):
# ... upsert data ...
if not self._entity_vector_index_created:
self._create_entity_vector_index()
self._entity_vector_index_created = True
Enter the URL of a public GitHub repository