Skip to content

Commit 0127e09

Browse files
committed
feat: support document and collection summary
1 parent 8efc635 commit 0127e09

45 files changed

Lines changed: 4317 additions & 2786 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ compose-logs:
140140
# Local development services
141141
.PHONY: run-backend run-frontend run-celery run-flower run-beat
142142
run-backend: migrate
143-
uvicorn aperag.app:app --host 0.0.0.0 --reload --log-config scripts/uvicorn-log-config.yaml
143+
uvicorn aperag.app:app --host 0.0.0.0 --log-config scripts/uvicorn-log-config.yaml
144144

145145
run-celery:
146146
celery -A config.celery worker -B -l INFO --pool=threads --concurrency=16

aperag/agent/rag_agent.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
from mcp_agent.config import LoggerSettings, MCPServerSettings, MCPSettings, OpenAISettings, Settings
2929
from mcp_agent.workflows.llm.augmented_llm_openai import OpenAIAugmentedLLM
3030

31-
os.environ["APERAG_API_KEY"] = "sk-test"
32-
os.environ["OPENAI_API_KEY"] = "sk-test"
31+
os.environ["APERAG_API_KEY"] = ""
32+
os.environ["OPENAI_API_KEY"] = ""
3333
os.environ["APERAG_URL"] = "http://localhost:8000/mcp/"
3434
os.environ["OPENAI_BASE_URL"] = "https://openrouter.ai/api/v1"
3535
os.environ["DEFAULT_MODEL"] = "gpt-4o-mini"
@@ -262,7 +262,7 @@ async def interactive_chat(self):
262262
continue
263263

264264
print("🔍 Searching knowledge base...")
265-
response = await llm.generate_str(question)
265+
response = await llm.generate(question)
266266
print(f"\n🤖 **Answer:**\n{response}")
267267

268268
except KeyboardInterrupt:

aperag/api/components/schemas/collection.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ collectionConfig:
148148
enable_knowledge_graph:
149149
type: boolean
150150
description: Whether to enable knowledge graph
151+
enable_summary:
152+
type: boolean
153+
description: Whether to enable summary generation
151154
embedding:
152155
$ref: './model.yaml#/modelSpec'
153156
completion:
@@ -271,6 +274,9 @@ collection:
271274
type: string
272275
description:
273276
type: string
277+
summary:
278+
type: string
279+
description: LLM-generated summary of the collection
274280
config:
275281
$ref: '#/collectionConfig'
276282
source:
@@ -281,6 +287,7 @@ collection:
281287
- ACTIVE
282288
- INACTIVE
283289
- DELETED
290+
- SUMMARY_GENERATING
284291
created:
285292
type: string
286293
format: date-time

aperag/api/components/schemas/document.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ document:
4444
- DELETION_IN_PROGRESS
4545
- FAILED
4646
- SKIPPED
47+
summary_index_status:
48+
type: string
49+
enum:
50+
- PENDING
51+
- CREATING
52+
- ACTIVE
53+
- DELETING
54+
- DELETION_IN_PROGRESS
55+
- FAILED
56+
- SKIPPED
4757
vector_index_updated:
4858
type: string
4959
format: date-time
@@ -56,6 +66,13 @@ document:
5666
type: string
5767
format: date-time
5868
description: Graph index last updated time
69+
summary_index_updated:
70+
type: string
71+
format: date-time
72+
description: Summary index last updated time
73+
summary:
74+
type: string
75+
description: Summary of the document
5976
config:
6077
type: string
6178
size:
@@ -101,6 +118,7 @@ rebuildIndexesRequest:
101118
- VECTOR
102119
- FULLTEXT
103120
- GRAPH
121+
- SUMMARY
104122
description: Types of indexes to rebuild
105123
minItems: 1
106124
required:

aperag/api/openapi.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ paths:
4343
$ref: './paths/collections.yaml#/collections'
4444
/collections/{collection_id}:
4545
$ref: './paths/collections.yaml#/collection'
46+
/collections/{collection_id}/summary/generate:
47+
$ref: './paths/collections.yaml#/summary_generate'
4648
/collections/{collection_id}/documents:
4749
$ref: './paths/collections.yaml#/documents'
4850
/collections/{collection_id}/documents/{document_id}:

aperag/api/paths/collections.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,41 @@ collection:
120120
schema:
121121
$ref: '../components/schemas/collection.yaml#/collection'
122122

123+
summary_generate:
124+
post:
125+
summary: Generate collection summary
126+
description: Trigger collection summary generation as background task
127+
security:
128+
- BearerAuth: []
129+
parameters:
130+
- name: collection_id
131+
in: path
132+
required: true
133+
schema:
134+
type: string
135+
responses:
136+
'200':
137+
description: Collection summary generation started
138+
content:
139+
application/json:
140+
schema:
141+
type: object
142+
properties:
143+
collection_id:
144+
type: string
145+
success:
146+
type: boolean
147+
message:
148+
type: string
149+
status:
150+
type: string
151+
'404':
152+
description: Collection not found
153+
content:
154+
application/json:
155+
schema:
156+
$ref: '../components/schemas/common.yaml#/failResponse'
157+
123158
documents:
124159
get:
125160
summary: List documents

aperag/app.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
import os
16+
1617
from fastapi import FastAPI
1718

1819
from aperag.exception_handlers import register_exception_handlers
@@ -65,6 +66,7 @@ async def health_check():
6566
# Only include test router in dev mode
6667
if os.environ.get("DEPLOYMENT_MODE") == "dev":
6768
from aperag.views.test import router as test_router
69+
6870
app.include_router(test_router, prefix="/api/v1")
6971

7072
# Mount the MCP server at /mcp path

aperag/config.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,7 @@ def __init__(self, **kwargs):
176176
# CELERY_BROKER_URL
177177
if not self.celery_broker_url:
178178
self.celery_broker_url = (
179-
f"redis://{self.redis_user}:{self.redis_password}"
180-
f"@{self.redis_host}:{self.redis_port}/0"
179+
f"redis://{self.redis_user}:{self.redis_password}@{self.redis_host}:{self.redis_port}/0"
181180
)
182181

183182
# CELERY_RESULT_BACKEND
@@ -187,20 +186,16 @@ def __init__(self, **kwargs):
187186
# MEMORY_REDIS_URL
188187
if not self.memory_redis_url:
189188
self.memory_redis_url = (
190-
f"redis://{self.redis_user}:{self.redis_password}"
191-
f"@{self.redis_host}:{self.redis_port}/1"
189+
f"redis://{self.redis_user}:{self.redis_password}@{self.redis_host}:{self.redis_port}/1"
192190
)
193191
# ES_HOST
194192
if not self.es_host:
195193
if self.es_user and self.es_password:
196194
self.es_host = (
197-
f"{self.es_protocol}://{self.es_user}:{self.es_password}"
198-
f"@{self.es_host_name}:{self.es_port}"
195+
f"{self.es_protocol}://{self.es_user}:{self.es_password}@{self.es_host_name}:{self.es_port}"
199196
)
200197
else:
201-
self.es_host = (
202-
f"{self.es_protocol}://{self.es_host_name}:{self.es_port}"
203-
)
198+
self.es_host = f"{self.es_protocol}://{self.es_host_name}:{self.es_port}"
204199
# Object store config
205200
if self.object_store_type == "local":
206201
self.object_store_local_config = LocalObjectStoreConfig()

aperag/db/models.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class CollectionStatus(str, Enum):
6262
INACTIVE = "INACTIVE"
6363
ACTIVE = "ACTIVE"
6464
DELETED = "DELETED"
65+
SUMMARY_GENERATING = "SUMMARY_GENERATING" # Currently generating collection summary
6566

6667

6768
class CollectionType(str, Enum):
@@ -82,6 +83,7 @@ class DocumentIndexType(str, Enum):
8283
VECTOR = "VECTOR"
8384
FULLTEXT = "FULLTEXT"
8485
GRAPH = "GRAPH"
86+
SUMMARY = "SUMMARY"
8587

8688

8789
class DocumentIndexStatus(str, Enum):
@@ -168,7 +170,8 @@ class Collection(Base):
168170

169171
id = Column(String(24), primary_key=True, default=lambda: "col" + random_id())
170172
title = Column(String(256), nullable=False)
171-
description = Column(Text, nullable=True)
173+
description = Column(Text, nullable=True) # User-provided description
174+
summary = Column(Text, nullable=True) # LLM-generated summary
172175
user = Column(String(256), nullable=False, index=True) # Add index for frequent queries
173176
status = Column(EnumColumn(CollectionStatus), nullable=False, index=True) # Add index for status queries
174177
type = Column(EnumColumn(CollectionType), nullable=False)

aperag/index/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class IndexType(Enum):
2424
VECTOR = "VECTOR"
2525
FULLTEXT = "FULLTEXT"
2626
GRAPH = "GRAPH"
27+
SUMMARY = "SUMMARY"
2728

2829

2930
class IndexStatus(Enum):

0 commit comments

Comments
 (0)