feat: новая функция
This commit is contained in:
@@ -30,7 +30,10 @@ RUN apt-get update && apt-get install -y \
|
|||||||
# Docker CLI НЕ устанавливаем - используем Docker Socket + dockerode SDK
|
# Docker CLI НЕ устанавливаем - используем Docker Socket + dockerode SDK
|
||||||
|
|
||||||
COPY package.json yarn.lock ./
|
COPY package.json yarn.lock ./
|
||||||
RUN yarn install --frozen-lockfile
|
RUN yarn config set npmRegistryServer https://registry.npmjs.org \
|
||||||
|
&& yarn config set registry https://registry.npmjs.org \
|
||||||
|
&& yarn config set network-timeout 600000 \
|
||||||
|
&& yarn install --frozen-lockfile
|
||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,28 @@ class VectorStore:
|
|||||||
pickle.dump(meta, f)
|
pickle.dump(meta, f)
|
||||||
self.index_cache[table_id] = (index, meta)
|
self.index_cache[table_id] = (index, meta)
|
||||||
|
|
||||||
|
def _clear(self, table_id):
|
||||||
|
idx_path = self._index_path(table_id)
|
||||||
|
meta_path = self._meta_path(table_id)
|
||||||
|
for path in (idx_path, meta_path):
|
||||||
|
if os.path.exists(path):
|
||||||
|
try:
|
||||||
|
os.remove(path)
|
||||||
|
except Exception as exc:
|
||||||
|
print(f"[WARN] Failed to remove {path}: {exc}")
|
||||||
|
self.index_cache.pop(table_id, None)
|
||||||
|
|
||||||
|
def _ensure_index_dimension(self, table_id, index, dim):
|
||||||
|
if index is None:
|
||||||
|
return index
|
||||||
|
|
||||||
|
if index.d == dim:
|
||||||
|
return index
|
||||||
|
|
||||||
|
print(f"[WARN] Dimension mismatch for table {table_id}: index.d={index.d}, expected={dim}. Resetting index.")
|
||||||
|
self._clear(table_id)
|
||||||
|
return None
|
||||||
|
|
||||||
def upsert(self, table_id, rows: List[Dict]):
|
def upsert(self, table_id, rows: List[Dict]):
|
||||||
print(f"[DEBUG] VectorStore.upsert called: table_id={table_id}, rows_count={len(rows)}")
|
print(f"[DEBUG] VectorStore.upsert called: table_id={table_id}, rows_count={len(rows)}")
|
||||||
# rows: [{row_id, embedding, metadata}]
|
# rows: [{row_id, embedding, metadata}]
|
||||||
@@ -47,7 +69,14 @@ class VectorStore:
|
|||||||
index = faiss.IndexFlatL2(dim)
|
index = faiss.IndexFlatL2(dim)
|
||||||
meta = []
|
meta = []
|
||||||
else:
|
else:
|
||||||
print(f"[DEBUG] Using existing index")
|
dim = len(rows[0]['embedding'])
|
||||||
|
index = self._ensure_index_dimension(table_id, index, dim)
|
||||||
|
if index is None:
|
||||||
|
print(f"[DEBUG] Re-creating index after dimension mismatch: dim={dim}")
|
||||||
|
index = faiss.IndexFlatL2(dim)
|
||||||
|
meta = []
|
||||||
|
else:
|
||||||
|
print(f"[DEBUG] Using existing index")
|
||||||
|
|
||||||
# Удаляем дубликаты row_id
|
# Удаляем дубликаты row_id
|
||||||
existing_ids = {m['row_id'] for m in meta}
|
existing_ids = {m['row_id'] for m in meta}
|
||||||
@@ -78,6 +107,12 @@ class VectorStore:
|
|||||||
query = np.array([query_embedding]).astype('float32')
|
query = np.array([query_embedding]).astype('float32')
|
||||||
print(f"[DEBUG] Query shape: {query.shape}")
|
print(f"[DEBUG] Query shape: {query.shape}")
|
||||||
|
|
||||||
|
dim = query.shape[1]
|
||||||
|
index = self._ensure_index_dimension(table_id, index, dim)
|
||||||
|
if index is None:
|
||||||
|
print(f"[DEBUG] Index reset due to dimension mismatch, returning empty results")
|
||||||
|
return []
|
||||||
|
|
||||||
D, I = index.search(query, top_k)
|
D, I = index.search(query, top_k)
|
||||||
print(f"[DEBUG] FAISS search results - D: {D}, I: {I}")
|
print(f"[DEBUG] FAISS search results - D: {D}, I: {I}")
|
||||||
|
|
||||||
|
|||||||
@@ -26,14 +26,28 @@ const PORT = process.env.PORT || 3000;
|
|||||||
const wss = new WebSocket.Server({
|
const wss = new WebSocket.Server({
|
||||||
server,
|
server,
|
||||||
cors: {
|
cors: {
|
||||||
origin: ['http://localhost:5173', 'http://localhost:8000', 'http://127.0.0.1:5173', 'http://127.0.0.1:8000'],
|
origin: [
|
||||||
|
'http://localhost:5173',
|
||||||
|
'http://localhost:8000',
|
||||||
|
'http://localhost:9000',
|
||||||
|
'https://localhost:9443',
|
||||||
|
'http://127.0.0.1:5173',
|
||||||
|
'http://127.0.0.1:8000'
|
||||||
|
],
|
||||||
credentials: true
|
credentials: true
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Middleware
|
// Middleware
|
||||||
app.use(cors({
|
app.use(cors({
|
||||||
origin: ['http://localhost:5173', 'http://localhost:8000', 'http://127.0.0.1:5173', 'http://127.0.0.1:8000'],
|
origin: [
|
||||||
|
'http://localhost:5173',
|
||||||
|
'http://localhost:8000',
|
||||||
|
'http://localhost:9000',
|
||||||
|
'https://localhost:9443',
|
||||||
|
'http://127.0.0.1:5173',
|
||||||
|
'http://127.0.0.1:8000'
|
||||||
|
],
|
||||||
credentials: true
|
credentials: true
|
||||||
}));
|
}));
|
||||||
app.use(express.json({ limit: '10mb' }));
|
app.use(express.json({ limit: '10mb' }));
|
||||||
|
|||||||
@@ -96,11 +96,15 @@ services:
|
|||||||
- LOG_LEVEL=INFO
|
- LOG_LEVEL=INFO
|
||||||
# 🆕 Улучшенный health check с fallback
|
# 🆕 Улучшенный health check с fallback
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: ["CMD-SHELL", "curl -f http://localhost:8001/health || curl -f http://localhost:8001/ || wget -q --spider http://localhost:8001/health || exit 1"]
|
test:
|
||||||
interval: 30s
|
- CMD-SHELL
|
||||||
timeout: 15s
|
- >-
|
||||||
retries: 15
|
python -c "import sys, urllib.request;
|
||||||
start_period: 180s
|
sys.exit(0 if urllib.request.urlopen('http://127.0.0.1:8001/health', timeout=5).getcode() == 200 else 1)"
|
||||||
|
interval: 20s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 5
|
||||||
|
start_period: 40s
|
||||||
|
|
||||||
backend:
|
backend:
|
||||||
image: digital_legal_entitydle-backend:latest
|
image: digital_legal_entitydle-backend:latest
|
||||||
@@ -188,7 +192,17 @@ services:
|
|||||||
volumes:
|
volumes:
|
||||||
- /etc/letsencrypt:/etc/letsencrypt
|
- /etc/letsencrypt:/etc/letsencrypt
|
||||||
- /var/www/certbot:/var/www/certbot
|
- /var/www/certbot:/var/www/certbot
|
||||||
command: certonly --webroot --webroot-path=/var/www/certbot --email ${EMAIL} --agree-tos --no-eff-email -d ${DOMAIN}
|
command: >-
|
||||||
|
certonly
|
||||||
|
--webroot
|
||||||
|
--webroot-path=/var/www/certbot
|
||||||
|
--email ${EMAIL}
|
||||||
|
--agree-tos
|
||||||
|
--no-eff-email
|
||||||
|
--non-interactive
|
||||||
|
--keep-until-expiring
|
||||||
|
--expand
|
||||||
|
-d ${DOMAIN}
|
||||||
depends_on:
|
depends_on:
|
||||||
- frontend-nginx
|
- frontend-nginx
|
||||||
|
|
||||||
@@ -217,7 +231,7 @@ services:
|
|||||||
- backend
|
- backend
|
||||||
- frontend
|
- frontend
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: ["CMD", "curl", "-f", "http://localhost:80/health", "||", "curl", "-f", "https://localhost:443/health", "||", "exit", "1"]
|
test: ["CMD-SHELL", "curl -k -f https://127.0.0.1/health || curl -f http://127.0.0.1/health || exit 1"]
|
||||||
interval: 30s
|
interval: 30s
|
||||||
timeout: 10s
|
timeout: 10s
|
||||||
retries: 5
|
retries: 5
|
||||||
|
|||||||
Reference in New Issue
Block a user