Use a hybrid pipeline that first runs a semantic vector search, then enriches the top‑k results with a GraphRAG traversal to pull relational entity context. The combined relevance score is a weighted sum of the vector similarity and the graph‑based relevance.
Step‑by‑step implementation
1. Embed documents – Use sentence‑transformers all-MiniLM-L6-v2 (or a 2026 MLLM encoder) to generate 768‑dim vectors.
2. Load vectors – Upsert into Pinecone (v3) with metric="cosine" and metadata={"entity_id": id}.
3. Create graph – Ingest the same entities into Neo4j (5.x) using MERGE (e:Entity {id:id}) and relationships via MERGE (e)-[:RELATED_TO {type:rel_type, weight:w}]->(f).
4. Hybrid query –
```python
from langchain.vectorstores import Pinecone
from langchain.graphs import Neo4jGraph
# Vector part
vec_results = Pinecone.from_existing_index("my-index").similarity_search(query, top_k=10)
top_ids = [r.metadata["entity_id"] for r in vec_results]
# Graph part
graph = Neo4jGraph(url="bolt://localhost:7687", auth=("neo4j", "pwd"))
cypher = """
MATCH (e:Entity)-[r:RELATED_TO1..2]-(n)
WHERE e.id IN $ids
RETURN e.id AS src, collect({target:n.id, weight:r.weight}) AS rels
"""
graph_results = graph.query(cypher, ids=top_ids)
```
5. Score fusion – Compute final_score = α vec_score + (1-α) * graph_score where α≈0.6 works well for most RAG use‑cases.
6. Prompt construction – Append the retrieved relational snippets (e.g., "Entity A is a subsidiary of Entity B") to the LLM prompt.
Quick comparison
| Component | Tool | Key params |
|---|---|---|
| Vector store | Pinecone (v3) | metric=cosine, top_k=10 |
| Graph DB | Neo4j (5.x) | depth=2, rel_weight=0.4 |
| Fusion | Custom scorer | α=0.6 |
Adjust top_k, depth, and α based on latency budget and domain density; typical end‑to‑end latency stays under 300 ms for a 10‑k vector pool and a 2‑hop graph traversal.