谷歌
谷歌向量存储 #
基类:EventBasePydanticVectorStore
Google GenerativeAI 向量存储。
目前,它在服务器端计算嵌入向量。
示例:
google_vector_store = GoogleVectorStore.from_corpus( corpus_id="my-corpus-id", include_metadata=True, metadata_keys=['file_name', 'creation_date'] ) index = VectorStoreIndex.from_vector_store( vector_store=google_vector_store )
属性:
| 名称 | 类型 | 描述 |
|---|---|---|
corpus_id |
str
|
该向量存储实例将读取和写入的语料库ID。 |
include_metadata |
bool
|
指示是否在查询结果中包含自定义元数据。默认为 False。 |
metadata_keys |
Optional[List[str]]
|
指定当 include_metadata 设为 True 时,要在查询结果中包含哪些元数据键。如果为 None,则包含所有元数据键。默认为 None。 |
workflows/handler.py 中的源代码llama_index/vector_stores/google/base.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 | |
corpus_id
class-attribute
instance-attribute
#
corpus_id: str = Field(frozen=True)
该向量存储实例正在使用的语料库ID。
from_corpus
classmethod
#
from_corpus(*, corpus_id: str, include_metadata: bool = False, metadata_keys: Optional[List[str]] = None) -> GoogleVectorStore
创建一个指向现有语料库的实例。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
corpus_id
|
str
|
谷歌服务器上现有语料库的ID。 |
required |
include_metadata
|
bool
|
指定是否在查询结果中包含自定义元数据。默认为 False,表示元数据将不会被包含。 |
False
|
metadata_keys
|
Optional[List[str]]
|
指定当 include_metadata 设为 True 时,要在查询结果中包含哪些元数据键。如果为 None,则包含所有元数据键。默认为 None。 |
None
|
返回:
| 类型 | 描述 |
|---|---|
GoogleVectorStore
|
指向指定语料库的向量存储实例。 |
workflows/handler.py 中的源代码llama_index/vector_stores/google/base.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | |
create_corpus
classmethod
#
create_corpus(*, corpus_id: Optional[str] = None, display_name: Optional[str] = None) -> GoogleVectorStore
创建一个指向新创建语料库的实例。
示例:
store = GoogleVectorStore.create_corpus() print(f"已创建语料库,ID为: {store.corpus_id})
store = GoogleVectorStore.create_corpus( display_name="我的第一个语料库" )
store = GoogleVectorStore.create_corpus( corpus_id="my-corpus-1", display_name="我的第一个语料库" )
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
corpus_id
|
Optional[str]
|
要创建的新语料库的ID。如果未提供,Google服务器将为您生成一个。 |
None
|
display_name
|
Optional[str]
|
语料库标题。如果未提供,Google服务器将为您提供一个。 |
None
|
返回:
| 类型 | 描述 |
|---|---|
GoogleVectorStore
|
指向指定语料库的向量存储实例。 |
workflows/handler.py 中的源代码llama_index/vector_stores/google/base.py
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | |
add #
add(nodes: List[BaseNode], **add_kwargs: Any) -> List[str]
向向量存储中添加带嵌入的节点。
如果一个节点拥有源节点,将使用源节点的ID来创建文档。否则,将使用该语料库的默认文档来容纳该节点。
此外,如果源节点具有元数据字段"file_name", 该字段将被用作文档的标题。如果源节点没有 此字段,Google服务器将为文档分配一个标题。
示例
存储 = GoogleVectorStore.from_corpus(语料库标识="123") 存储.添加([ 文本节点( 文本="你好,我亲爱的", 关系={ 节点关系.来源: 相关节点信息( 节点标识="文档-456", 元数据={"文件名称": "文档-456的标题"}, ) }, ), 文本节点( 文本="再见,我的宝贝", 关系={ 节点关系.来源: 相关节点信息( 节点标识="文档-456", 元数据={"文件名称": "文档-456的标题"}, ) }, ), ])
以上代码将创建一个ID为doc-456、标题为Title for doc-456的文档。该文档将包含两个节点。
workflows/handler.py 中的源代码llama_index/vector_stores/google/base.py
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 | |
delete #
delete(ref_doc_id: str, **delete_kwargs: Any) -> None
根据 ref_doc_id 删除节点。
底层节点和文档都将从谷歌服务器中删除。
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
ref_doc_id
|
str
|
要删除的文档ID。 |
required |
workflows/handler.py 中的源代码llama_index/vector_stores/google/base.py
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 | |
query #
query(query: VectorStoreQuery, **kwargs: Any) -> VectorStoreQueryResult
查询向量存储。
示例
store = GoogleVectorStore.from_corpus(corpus_id="123") store.query( query=VectorStoreQuery( query_str="What is the meaning of life?", # 仅包含此作者的节点 filters=MetadataFilters( filters=[ ExactMatchFilter( key="author", value="Arthur Schopenhauer", ) ] ), # 仅从这些文档中搜索。如果未提供, # 则搜索整个语料库。 doc_ids=["doc-456"], similarity_top_k=3, ) )
参数:
| 名称 | 类型 | 描述 | 默认 |
|---|---|---|---|
query
|
VectorStoreQuery
|
请参阅 |
required |
workflows/handler.py 中的源代码llama_index/vector_stores/google/base.py
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 | |
set_google_config #
set_google_config(*, api_endpoint: Optional[str] = None, user_agent: Optional[str] = None, page_size: Optional[int] = None, auth_credentials: Optional[Credentials] = None, **kwargs: Any) -> None
设置 Google Generative AI API 的配置。
参数是可选的,通常默认值即可正常工作。
如果提供参数,它们将覆盖 Config 类中的默认值。
更多详细信息请参阅 genai_extension.py 中的文档字符串。
auth_credentials: Optional["credentials.Credentials"] = None,
使用此参数传递 Google 身份验证凭据,例如使用服务账号。
有关身份验证凭据文档请参考:
https://developers.google.com/identity/protocols/oauth2/service-account#creatinganaccount。
示例
从 google.oauth2 导入服务账户凭据 凭据 = service_account.Credentials.from_service_account_file( "/路径/到/service.json", 作用域=[ "https://www.googleapis.com/auth/cloud-platform", "https://www.googleapis.com/auth/generative-language.retriever", ], ) 设置谷歌配置(认证凭据=凭据)
workflows/handler.py 中的源代码llama_index/vector_stores/google/base.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
选项: 成员:- GoogleVectorStore