import time
import uuid
print("[Setup] Loading VantaDB & Emulated LangChain Modules...")
import vantadb_py as vantadb
db = vantadb.VantaDB("./local_vanta_data", memory_limit_bytes=128_000_000, read_only=False)
raw_documents = [
"VantaDB is a deeply embedded database written in Rust.",
"Using multiple databases (Vector, Graph, Relational) creates a glue-code nightmare.",
"By compiling the database via PyO3, Python apps can query vectors with Zero-Copy overhead.",
"Resource governance automatically shifts HNSW heaps to Disk (MMAP) when RAM is low.",
]
def hook_embed_documents(texts):
return [[0.1, 0.4, 0.6] for _ in texts]
print("[RAG] Ingesting documents...")
start_time = time.perf_counter()
embeddings = hook_embed_documents(raw_documents)
for i, text in enumerate(raw_documents):
db.insert(
i + 1,
text,
embeddings[i],
fields={
"doc_id": str(uuid.uuid4()),
"content": text,
"category": "architecture",
"processed": True,
},
)
print(
f"[RAG] Ingestion completed in {(time.perf_counter() - start_time) * 1000:.2f} ms"
)
user_query = "How does it avoid the glue-code problem in Python?"
query_embedding = hook_embed_documents([user_query])[0]
print("\n[RAG] Searching for context...")
search_start = time.perf_counter()
results = db.search(query_embedding, top_k=2)
search_end = time.perf_counter()
print(f"[RAG] Semantic search took {(search_end - search_start) * 1000:.3f} ms.")
context_chunks = []
for (node_id, _distance) in results:
node = db.get(node_id) or {}
fields = node.get("fields") or {}
content = fields.get("content") or ""
if content:
context_chunks.append(str(content))
context = "\n".join(context_chunks)
prompt = f"Answer the user's question using the context.\n\nContext:\n{context}\n\nQuestion: {user_query}"
print(f"\n[Generated Prompt Output to LLM]\n{prompt}\n")
print("✅ Local RAG pipeline executed successfully without leaving the Python process.")