mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-09-22 08:02:21 +02:00
Squash Odysseus development history
This commit is contained in:
+43
-11
@@ -5,6 +5,7 @@ from dataclasses import dataclass
|
||||
from typing import List, Dict, Any
|
||||
|
||||
from src.rag_manager import RAGManager
|
||||
from src.constants import CHROMA_DIR
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -34,7 +35,7 @@ class DocsService:
|
||||
results = await service.query("what is async await?")
|
||||
"""
|
||||
|
||||
def __init__(self, persist_dir: str = "data/chroma"):
|
||||
def __init__(self, persist_dir: str = CHROMA_DIR):
|
||||
self.rag = RAGManager(persist_directory=persist_dir)
|
||||
|
||||
async def query(self, query: str, top_k: int = 5) -> List[DocChunk]:
|
||||
@@ -49,15 +50,46 @@ class DocsService:
|
||||
List of DocChunk objects
|
||||
"""
|
||||
results = self.rag.search(query, k=top_k)
|
||||
return [
|
||||
DocChunk(
|
||||
text=r.get("text", r.get("content", "")),
|
||||
source=r.get("source", r.get("metadata", {}).get("source", "unknown")),
|
||||
score=r.get("score", 0.0),
|
||||
metadata=r.get("metadata"),
|
||||
chunks = []
|
||||
|
||||
for result in results:
|
||||
if not isinstance(result, dict):
|
||||
continue
|
||||
|
||||
metadata = result.get("metadata")
|
||||
if not isinstance(metadata, dict):
|
||||
metadata = {}
|
||||
|
||||
text = result.get("document")
|
||||
if text is None:
|
||||
text = result.get("text")
|
||||
if text is None:
|
||||
text = result.get("content")
|
||||
if text is None:
|
||||
text = ""
|
||||
|
||||
source = result.get("source")
|
||||
if source is None:
|
||||
source = metadata.get("source")
|
||||
if source is None:
|
||||
source = "unknown"
|
||||
|
||||
score = result.get("similarity")
|
||||
if score is None:
|
||||
score = result.get("score")
|
||||
if score is None:
|
||||
score = 0.0
|
||||
|
||||
chunks.append(
|
||||
DocChunk(
|
||||
text=text,
|
||||
source=source,
|
||||
score=score,
|
||||
metadata=metadata,
|
||||
)
|
||||
)
|
||||
for r in results
|
||||
]
|
||||
|
||||
return chunks
|
||||
|
||||
async def index(self, directory: str) -> IndexResult:
|
||||
"""
|
||||
@@ -71,8 +103,8 @@ class DocsService:
|
||||
"""
|
||||
result = self.rag.index_personal_documents(directory)
|
||||
return IndexResult(
|
||||
indexed=result.get("indexed", 0),
|
||||
failed=result.get("failed", 0),
|
||||
indexed=result.get("indexed_count", result.get("indexed", 0)),
|
||||
failed=result.get("failed_count", result.get("failed", 0)),
|
||||
errors=result.get("errors", []),
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user