create AI memory infrastructure

This commit is contained in:
Dobromir Popov 2024-03-06 19:17:28 +02:00
parent 4100fe5877
commit c6899e4ded
5 changed files with 106 additions and 0 deletions

6
store-all/api/Dockerfile Normal file
View File

@ -0,0 +1,6 @@
FROM python:3.9-slim
WORKDIR /usr/src/app
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD ["python", "app.py"]

30
store-all/api/app.py Normal file
View File

@ -0,0 +1,30 @@
from flask import Flask, jsonify, request
from neo4j import GraphDatabase
from pymilvus import connections, Collection
app = Flask(__name__)
# Neo4j Connection
neo4j_driver = GraphDatabase.driver("bolt://neo4j:7687", auth=("neo4j", "testpassword"))
# Milvus Connection
connections.connect("default", host="milvus", port="19530")
@app.route('/')
def home():
return jsonify({'message': 'Hello, World!'})
@app.route('/neo4j_test')
def neo4j_test():
with neo4j_driver.session() as session:
result = session.run("MATCH (n) RETURN count(n) AS count")
count = result.single()["count"]
return jsonify({'neo4j_node_count': count})
@app.route('/milvus_test')
def milvus_test():
collections = Collection.list()
return jsonify({'milvus_collections': collections})
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)

View File

@ -0,0 +1,4 @@
Flask==2.0.3
neo4j==4.4.1
pymilvus==2.0.2
gunicorn==20.1.0

View File

@ -0,0 +1,45 @@
version: '3.8'
services:
neo4j:
image: neo4j:latest
container_name: neo4j
ports:
- "7474:7474" # HTTP
- "7687:7687" # Bolt
volumes:
- ./neo4j/data:/data
- ./neo4j/logs:/logs
- ./neo4j/import:/var/lib/neo4j/import
- ./neo4j/plugins:/plugins
environment:
NEO4J_AUTH: neo4j/testpassword
milvus:
image: milvusdb/milvus:v2.0.0
container_name: milvus
ports:
- "19530:19530" # Milvus default port
volumes:
- ./milvus/db:/var/lib/milvus/db
- ./milvus/conf:/var/lib/milvus/conf
- ./milvus/logs:/var/lib/milvus/logs
environment:
TZ: UTC
api:
build: ./api
container_name: api
ports:
- "5000:5000"
volumes:
- ./api:/usr/src/app
depends_on:
- neo4j
- milvus
environment:
NEO4J_URI: bolt://neo4j:7687
NEO4J_USER: neo4j
NEO4J_PASSWORD: testpassword
MILVUS_HOST: milvus
MILVUS_PORT: 19530

21
store-all/story.md Normal file
View File

@ -0,0 +1,21 @@
<!-- Graph Database -->
Rich Relationships: Graph databases excel at managing highly interconnected data, allowing you to efficiently model, store, and query complex networks of relationships.
Performance: They are optimized for traversing complex relationships and can perform deep queries very fast, unlike traditional databases where join-intensive queries can be slow.
Flexibility: They typically allow for schema-less or schema-flexible data, making them adaptable to evolving data models without significant redesign.
Intuitive Query Language: Many graph databases use query languages like Cypher (Neo4j), which are powerful yet readable, making complex queries more straightforward to construct and understand.
Cons:
Scalability: Horizontal scaling can be challenging with graph databases, as they are inherently designed for deep, computationally intense traversals.
Specialized Knowledge: The need for understanding specific query languages and graph theory can steepen the learning curve.
Resource Intensity: Maintaining high-performance levels, especially with very large datasets, can require significant computational resources.
Python is widely adopted in the data science community, offering extensive libraries and frameworks for both graph databases (like py2neo for Neo4j) and vector databases (like milvus-py for Milvus). Its particularly strong in analytics, machine learning, and AI, which aligns well with the use cases of vector databases.