repository.py 1016 B

12345678910111213141516171819202122232425262728
  1. from .models import Document, GraphChunk, ChunkRelations, QUERY
  2. class AsyncNeo4jRepository:
  3. def __init__(self, neo4j):
  4. self.neo4j = neo4j
  5. async def add_document_with_chunk(
  6. self, doc: Document, chunk: GraphChunk, relations: ChunkRelations
  7. ):
  8. async with self.neo4j.session() as session:
  9. await session.run(
  10. QUERY,
  11. milvus_id=chunk.milvus_id,
  12. doc_id=doc.doc_id,
  13. dataset_id=doc.dataset_id,
  14. chunk_id=chunk.chunk_id,
  15. topic=chunk.topic,
  16. domain=chunk.domain,
  17. text_type=chunk.text_type,
  18. task_type=chunk.task_type,
  19. entities=relations.entities,
  20. concepts=relations.concepts,
  21. keywords=relations.keywords,
  22. domain_name=relations.domain,
  23. topic_name=relations.topic,
  24. )
  25. print(f"✅ {doc.doc_id} - {chunk.chunk_id} 已写入 Neo4j (async)")