Skip to main content

Graph-based AI memory system with Neo4j, recall scoring, and conflict analysis

Project description

Neur0 (nyron-ai)

Neur0 is a graph-based AI memory system designed for long-term personalization. It uses Neo4j to build isolated user subgraphs, resolves memory conflicts using semantic analysis, ranks retrieved memories using recall scoring, and keeps short-term context utilizing MongoDB.


Features

  • Graph-Based Memory: Build highly structured, isolated memory subgraphs for individual users.
  • Semantic Conflict Resolution: Automatically detect when new facts contradict existing memories and mark old facts as conflicted. -Recall Scoring: Rank memories dynamically based on a combination of semantic similarity, recency, and reinforcement (access frequency). -Short-Term Context: Manage short-term context and resolve pronouns/references using MongoDB. -OpenAI Integration: Cleanly extract facts and embeddings using OpenAI models. -Built-in API Server: Instantly run a FastAPI server using the CLI to add, search, and manage memories via HTTP requests.

Prerequisites

  • Python: >=3.9
  • Neo4j Database: A running instance (e.g. Neo4j Desktop, AuraDB, or Docker).
  • MongoDB (Optional): Required if you want to enable the short-term memory store.
  • OpenAI API Key: Required for fact extraction, query resolution, and embeddings.

Installation

You can install Neur0 from PyPI:

pip install nyron-ai

For local development and testing, clone the repository and run:

pip install -e .

Quickstart

1. Configure Environment Variables

Create a .env file in your project root with your database credentials and API keys:

OPENAI_API_KEY=your-openai-key
NEO4J_URI=bolt://localhost:7687
NEO4J_USERNAME=neo4j
NEO4J_PASSWORD=password

# Optional: MongoDB for short-term memory
MONGO_URI=mongodb://localhost:27017
MONGO_DB=neur0

2. Python Code Usage

Here is how to initialize the memory client, save a memory, and query it:

import asyncio
from neuro import (
    MemoryClient,
    Neo4jGraphStore,
    MongoStore,
    OpenAIProvider,
    OpenAIEmbeddingProvider,
)

async def main():
    # 1. Initialize Stores
    graph_store = Neo4jGraphStore(
        uri="bolt://localhost:7687",
        username="neo4j",
        password="password",
    )
    graph_store.initialize()

    # Optional MongoDB short-term store
    mongo_store = MongoStore(uri="mongodb://localhost:27017", db_name="neur0")
    await mongo_store.initialize()

    # 2. Setup AI Providers
    llm = OpenAIProvider(api_key="your-api-key", model="gpt-4o-mini")
    embedder = OpenAIEmbeddingProvider(api_key="your-api-key", model="text-embedding-3-small")

    # 3. Create Memory Client
    memory = MemoryClient(
        graph_store=graph_store,
        llm=llm,
        embedder=embedder,
        short_term_store=mongo_store,
    )

    # 4. Save a Memory
    user_id = "user_128r"
    result = await memory.add(
        user_id=user_id,
        message="I studied computer science at Cambridge University.",
    )
    print("Saved facts:", result["saved_count"])

    # 5. Search memories
    search_results = await memory.search(
        user_id=user_id,
        query="Where did I go to college?",
    )
    for res in search_results:
        fact = res["fact"]
        print(f"Fact: {fact.subject} {fact.predicate} {fact.object}")
        print(f"Recall Score: {res['recall_score']}")

    # Clean up connections
    graph_store.close()
    mongo_store.close()

if __name__ == "__main__":
    asyncio.run(main())

Running the API Server

Neur0 includes a built-in command line utility to start a FastAPI backend.

Simply run:

neuro-api

The API will start running at http://localhost:8000.

Available Endpoints

  • POST /add_memory: Add a new user message, extract facts, and handle conflicts.
    {
      "user_id": "user_128r",
      "message": "I study computer science at Cambridge."
    }
    
  • POST /search_memory: Search and retrieve relevant memories.
    {
      "user_id": "user_128r",
      "query": "Where do I study?",
      "limit": 5
    }
    
  • DELETE /delete_subgraph/{user_id}: Delete all graph nodes and memories for a specific user.

License

MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nyron_ai-0.1.2.tar.gz (24.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nyron_ai-0.1.2-py3-none-any.whl (22.4 kB view details)

Uploaded Python 3

File details

Details for the file nyron_ai-0.1.2.tar.gz.

File metadata

  • Download URL: nyron_ai-0.1.2.tar.gz
  • Upload date:
  • Size: 24.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for nyron_ai-0.1.2.tar.gz
Algorithm Hash digest
SHA256 6bcb21bb7f4c6d4359aecede1586ecaae2be2bfc067833a9c915d33116306a3a
MD5 28a2838d0864b149a751735960dd7401
BLAKE2b-256 c7bd2f206b68651127a7fbe9b14b96a2ee871a0b610c32adeb0307496a960557

See more details on using hashes here.

File details

Details for the file nyron_ai-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: nyron_ai-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 22.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for nyron_ai-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4beb7c75b096458ce358dd933d4049dd1312d73a3e14b05ee423c1867663dee8
MD5 ccb1c8673b2b229a7366c4846b7aa690
BLAKE2b-256 653c3a00a748db47699bc21785ec8064cafb4aa52eabbb247945109da57730ec

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page