Skip to content

Commit 9d8bb5d

Browse files
Move firestore integration into integrations package
1 parent 5645fe8 commit 9d8bb5d

7 files changed

Lines changed: 70 additions & 305 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from __future__ import annotations
16+
17+
"""Firestore integrations for ADK."""

src/google/adk/firestore_database_runner.py renamed to src/google/adk/integrations/firestore/firestore_database_runner.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
from typing import Optional
1919
from typing import TYPE_CHECKING
2020

21-
from .artifacts.gcs_artifact_service import GcsArtifactService
22-
from .memory.firestore_memory_service import FirestoreMemoryService
23-
from .runners import Runner
24-
from .sessions.firestore_session_service import FirestoreSessionService
21+
from ...artifacts.gcs_artifact_service import GcsArtifactService
22+
from ...runners import Runner
23+
from .firestore_memory_service import FirestoreMemoryService
24+
from .firestore_session_service import FirestoreSessionService
2525

2626
if TYPE_CHECKING:
27-
from .agents.base_agent import BaseAgent
27+
from ...agents.base_agent import BaseAgent
2828

2929

3030
def create_firestore_runner(

src/google/adk/memory/firestore_memory_service.py renamed to src/google/adk/integrations/firestore/firestore_memory_service.py

Lines changed: 28 additions & 219 deletions
Original file line numberDiff line numberDiff line change
@@ -24,223 +24,44 @@
2424

2525
from typing_extensions import override
2626

27-
from . import _utils
28-
from ..events.event import Event
29-
from .base_memory_service import BaseMemoryService
30-
from .base_memory_service import SearchMemoryResponse
31-
from .memory_entry import MemoryEntry
27+
from ...memory import _utils
28+
from ...events.event import Event
29+
from ...memory.base_memory_service import BaseMemoryService
30+
from ...memory.base_memory_service import SearchMemoryResponse
31+
from ...memory.memory_entry import MemoryEntry
3232

3333
if TYPE_CHECKING:
3434
from google.cloud import firestore
3535

36-
from ..sessions.session import Session
36+
from ...sessions.session import Session
3737

3838
logger = logging.getLogger("google_adk." + __name__)
3939

4040
DEFAULT_EVENTS_COLLECTION = "events"
4141

42-
# Standard English stop words
4342
DEFAULT_STOP_WORDS = {
44-
"a",
45-
"an",
46-
"the",
47-
"and",
48-
"or",
49-
"but",
50-
"if",
51-
"then",
52-
"else",
53-
"to",
54-
"of",
55-
"in",
56-
"on",
57-
"for",
58-
"with",
59-
"is",
60-
"are",
61-
"was",
62-
"were",
63-
"be",
64-
"been",
65-
"being",
66-
"have",
67-
"has",
68-
"had",
69-
"do",
70-
"does",
71-
"did",
72-
"can",
73-
"could",
74-
"will",
75-
"would",
76-
"should",
77-
"shall",
78-
"may",
79-
"might",
80-
"must",
81-
"up",
82-
"down",
83-
"out",
84-
"in",
85-
"over",
86-
"under",
87-
"again",
88-
"further",
89-
"then",
90-
"once",
91-
"here",
92-
"there",
93-
"when",
94-
"where",
95-
"why",
96-
"how",
97-
"all",
98-
"any",
99-
"both",
100-
"each",
101-
"few",
102-
"more",
103-
"most",
104-
"other",
105-
"some",
106-
"such",
107-
"no",
108-
"nor",
109-
"not",
110-
"only",
111-
"own",
112-
"same",
113-
"so",
114-
"than",
115-
"too",
116-
"very",
117-
"i",
118-
"me",
119-
"my",
120-
"myself",
121-
"we",
122-
"our",
123-
"ours",
124-
"ourselves",
125-
"you",
126-
"your",
127-
"yours",
128-
"yourself",
129-
"yourselves",
130-
"he",
131-
"him",
132-
"his",
133-
"himself",
134-
"she",
135-
"her",
136-
"hers",
137-
"herself",
138-
"it",
139-
"its",
140-
"itself",
141-
"they",
142-
"them",
143-
"their",
144-
"theirs",
145-
"themselves",
146-
"what",
147-
"which",
148-
"who",
149-
"whom",
150-
"this",
151-
"that",
152-
"these",
153-
"those",
154-
"am",
155-
"is",
156-
"are",
157-
"was",
158-
"were",
159-
"be",
160-
"been",
161-
"being",
162-
"have",
163-
"has",
164-
"had",
165-
"having",
166-
"do",
167-
"does",
168-
"did",
169-
"doing",
170-
"a",
171-
"an",
172-
"the",
173-
"and",
174-
"but",
175-
"if",
176-
"or",
177-
"because",
178-
"as",
179-
"until",
180-
"while",
181-
"of",
182-
"at",
183-
"by",
184-
"for",
185-
"with",
186-
"about",
187-
"against",
188-
"between",
189-
"into",
190-
"through",
191-
"during",
192-
"before",
193-
"after",
194-
"above",
195-
"below",
196-
"to",
197-
"from",
198-
"up",
199-
"down",
200-
"in",
201-
"out",
202-
"on",
203-
"off",
204-
"over",
205-
"under",
206-
"again",
207-
"further",
208-
"then",
209-
"once",
210-
"here",
211-
"there",
212-
"when",
213-
"where",
214-
"why",
215-
"how",
216-
"all",
217-
"any",
218-
"both",
219-
"each",
220-
"few",
221-
"more",
222-
"most",
223-
"other",
224-
"some",
225-
"such",
226-
"no",
227-
"nor",
228-
"not",
229-
"only",
230-
"own",
231-
"same",
232-
"so",
233-
"than",
234-
"too",
235-
"very",
236-
"s",
237-
"t",
238-
"can",
239-
"will",
240-
"just",
241-
"don",
242-
"should",
243-
"now",
43+
"a", "an", "the", "and", "or", "but", "if", "then", "else", "to", "of",
44+
"in", "on", "for", "with", "is", "are", "was", "were", "be", "been",
45+
"being", "have", "has", "had", "do", "does", "did", "can", "could",
46+
"will", "would", "should", "shall", "may", "might", "must", "up", "down",
47+
"out", "in", "over", "under", "again", "further", "then", "once", "here",
48+
"there", "when", "where", "why", "how", "all", "any", "both", "each",
49+
"few", "more", "most", "other", "some", "such", "no", "nor", "not",
50+
"only", "own", "same", "so", "than", "too", "very", "i", "me", "my",
51+
"myself", "we", "our", "ours", "ourselves", "you", "your", "yours",
52+
"yourself", "yourselves", "he", "him", "his", "himself", "she", "her",
53+
"hers", "herself", "it", "its", "itself", "they", "them", "their",
54+
"theirs", "themselves", "what", "which", "who", "whom", "this", "that",
55+
"these", "those", "am", "is", "are", "was", "were", "be", "been", "being",
56+
"have", "has", "had", "having", "do", "does", "did", "doing", "a", "an",
57+
"the", "and", "but", "if", "or", "because", "as", "until", "while", "of",
58+
"at", "by", "for", "with", "about", "against", "between", "into",
59+
"through", "during", "before", "after", "above", "below", "to", "from",
60+
"up", "down", "in", "out", "on", "off", "over", "under", "again",
61+
"further", "then", "once", "here", "there", "when", "where", "why", "how",
62+
"all", "any", "both", "each", "few", "more", "most", "other", "some",
63+
"such", "no", "nor", "not", "only", "own", "same", "so", "than", "too",
64+
"very", "s", "t", "can", "will", "just", "don", "should", "now",
24465
}
24566

24667

@@ -288,8 +109,6 @@ async def _search_by_keyword(
288109
self, app_name: str, user_id: str, keyword: str
289110
) -> list[MemoryEntry]:
290111
"""Searches for events matching a single keyword."""
291-
# This requires a collection group index in Firestore for 'events' with
292-
# appName == X, userId == Y, and keywords array-contains Z.
293112
query = (
294113
self.client.collection_group(self.events_collection)
295114
.where("appName", "==", app_name)
@@ -326,26 +145,16 @@ async def search_memory(
326145
if not keywords:
327146
return SearchMemoryResponse()
328147

329-
# Search for each keyword concurrently
330148
tasks = [
331149
self._search_by_keyword(app_name, user_id, keyword)
332150
for keyword in keywords
333151
]
334152
results = await asyncio.gather(*tasks)
335153

336-
# Merge results and deduplicate by MemoryEntry content/author/timestamp
337-
# (MemoryEntry is not hashable by default if it contains complex objects,
338-
# so we might need to deduplicate by id if available, or by content string).
339-
# Since we convert Event to MemoryEntry, we don't have event.id in MemoryEntry
340-
# unless we add it. The Java code use custom hash/equals for MemoryEntry.
341-
# In Python, MemoryEntry is a Pydantic model. We can deduplicate by model_dump_json()
342-
# or by a custom key.
343154
seen = set()
344155
memories = []
345156
for result_list in results:
346157
for entry in result_list:
347-
# Deduplicate by a key of (author, content_text)
348-
# Content might be complex, so let's use its json representation or text
349158
content_text = ""
350159
if entry.content and entry.content.parts:
351160
content_text = " ".join(

0 commit comments

Comments
 (0)